fopen()fopen()
is not required to set errno
:
#if 0
fp = fopen (filePath , "rb");
if(!fp) {
perror(filePath);
exit(IO_ERR);
}
#else
errno = 0;
fp = fopen(filePath, "rb");
/* The cast void is required as ISO C forbids conditional expr with only one
* void side.
*/
if (!fp) {
errno ? perror(filePath) : (void) fputs("Error - failed to open file.", stderr);
exit(IO_ERR);
}
#endif
Use a compound literal for simplification:
As we're using C99, this:
SourceFile sourceFile = {
buffer,
lSize
};
return sourceFile;
can be simplified to just:
return (SourceFile) {buffer, lSize};
Does it matter if there are more than 3 arguments? Currently, the interpreter is ignoring them.
Question:
How will the user ever learn about the optional third argument? The usage message doesn't say anything about it.