by userbinator · 12y ago · 0 comments
FILE *f;
int i = 1;
...
if(argc < 2) {
f = stdin;
goto do_head;
}
...
while(i<argc) {
f = fopen(argv[i], "r");
/* check for failure to open */
...
do_head:
/* head'ing code goes here */
...
fclose(f);
i++;
}
That being said, OpenBSD code is still far more concise and readable than GNU; compare coreutils' head.c here:http://code.metager.de/source/xref/gnu/coreutils/src/head.c
GNU head has a bit more functionality, but I don't think the increase in complexity - nearly 10x more lines - is proportional to that.
http://www.opensource.apple.com/source/text_cmds/text_cmds-8...
(Although I think the use of malloc() and strcpy() to handle the -[0-9]+ case seems rather unnecessary...)