fgets
The fgets function seems to have different semantics on different systems after an EOF condition under Linux (glibc) and FreeBSD. Under Linux you can happily call fgets twice in a row and it will Just Workâ˘. Under FreeBSD, you'll have to say "Sorry!", i.e. clearerr, and it won't talk to you unless you do it. I haven't yet found out where this happens but I find this behavior rather annoying. The worst part is that this doesn't seem documented.
The following program illustrates the problem. Press Ctrl-D at the first prompt. Linux will try to read again the second time. FreeBSD won't unless you put a clearerr in there.
#include <stdio.h>
int main(int argc, const char **argv) {
char buffer[256];
fputs("What? ", stdout); fflush(stdout);
if (fgets(buffer, sizeof buffer, stdin) != NULL) {
fprintf(stdout, "Got 1: '%s'\n", buffer);
}
fputs("What? ", stdout); fflush(stdout);
if (fgets(buffer, sizeof buffer, stdin) != NULL) {
fprintf(stdout, "Got 2: '%s'\n", buffer);
}
return 0;
}