Skip to content

Commit 8fa6fa1

Browse files
committed
Accept no argument along with - for stdin
1 parent 736be43 commit 8fa6fa1

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ Usage
2424

2525
hostsblock [filterlist]
2626

27-
If the filterlist argument is `-`, hostsblock will read from stdin. For example,
27+
If the filterlist argument is `-` or omitted, hostsblock will read from stdin.
28+
For example,
2829

2930
curl -s https://www.fanboy.co.nz/r/fanboy-ultimate.txt | hostsblock -
3031

@@ -33,4 +34,6 @@ list, read the hosts file entries from it with hostsblock, and concatenate the
3334
original hosts file with the ad-blocking entries to create the actual hosts
3435
file:
3536

36-
curl -s https://www.fanboy.co.nz/r/fanboy-ultimate.txt | hostsblock - | cat /etc/hosts~ - > /etc/hosts
37+
curl -s https://www.fanboy.co.nz/r/fanboy-ultimate.txt |
38+
hostsblock |
39+
cat /etc/hosts~ - > /etc/hosts

hostsblock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ int main(int argc, char **argv)
114114
char rule[MAX_DOMAIN_RULE_LENGTH];
115115
char domain[MAX_DOMAIN_LENGTH] = { 0 };
116116

117-
if (argc != 2) {
117+
if (argc > 2) {
118118
fprintf(stderr, "usage: %s [filterlist]\n", argv[0]);
119119
return 1;
120120
}
121-
122-
if (!strncmp(argv[1], "-", 2)) list = stdin;
121+
122+
if (argc < 2 || !strncmp(argv[1], "-", 2)) list = stdin;
123123
else list = fopen(argv[1], "r");
124124

125125
if (list == NULL) {

0 commit comments

Comments
 (0)