M
Malcolm McLean
There's a slight difference with core programs.For many of the GNU coreutils programs (i.e. classic Unix "filter"
programs), stdio is the interface of last resort. Even if they use
buffered I/O, they typically open() the file first then use fdopen() to
get a FILE* from the descriptor if they want it.
It's a bit like the strdup() issue.
I normally write strdup like this
char *mystrdup(const char *str)
{
char *answer = malloc(strlen(str) + 1);
if(answer)
strcpy(answer, str);
return answer;
}
However if you write it like like this
char *superstrdup(const char *str)
{
size_t len = strlen(str);
char *answer = malloc(len + 1);
if(answer)
memcpy(answer, str, len+1);
return answer;
}
compilers will often emit more efficient code.
It's not normally worth the bother, but if you are implementing a
library function, it is worth it.
Similarly with core utilities. The few microseconds you can shave off
file activities by using unbuffered, hand optimised IO becomes worth
it, because the utility is run many millions of times.