address oft-noted 'bug'

This commit is contained in:
2022-08-24 17:08:34 -04:00
parent b3cd51242c
commit 3a849ed4c0
2 changed files with 4 additions and 52 deletions
-52
View File
@@ -1,52 +0,0 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* on some non-POSIX systems this may need to be "rb" */
#define READ_MODE "r"
const char *WHITESPACE = " \t\r\n";
/* This function checks if the *****REST****** of the file is blank. It does
* not rewind the file first. */
bool
file_is_blank(FILE *f){
int c;
while(strchr(WHITESPACE, (c = getc(f))) != NULL);
return c == EOF;
}
void
usage(char *name){
fprintf(stderr, "Usage: %s <file...>\n", argv[0]);
exit(1);
}
int main(int argc, char **argv){
char *argv0;
FILE *fp[argc-1];
int fd;
int i;
struct stat s;
argv0 = argv[0];
--argc; ++argv;
if(argc < 2)
usage(argv0);
for(i = 0; i < argc; ++i){
if((fp[i] = fopen(argv[i], READ_MODE)) == NULL){
fprintf(stderr,
"%s: %s: Error opening file for reading.\n",
argv0, argv[i]);
return 1;
}
}
/* UNREACHABLE */
return 0;
}