diff --git a/include/common.h b/include/common.h index d5c73c7..7269859 100644 --- a/include/common.h +++ b/include/common.h @@ -31,11 +31,14 @@ enum configurations { fprintf(stream, __VA_ARGS__); \ } while (0) +#define ERROR_MSG(a, b) \ + fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, (a), (b)) + #define PERROR_MACRO(s) do { \ int errnum = errno; \ char* err_msg = strerror(errnum); /* XXX: Thread race possible */ \ fflush(stdout); \ - fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, (s), err_msg); \ + ERROR_MSG((s), err_msg); \ } while (0) #define FATAL_ERROR_PRINT(...) do { \ diff --git a/src/main.c b/src/main.c index 405190c..689eee8 100644 --- a/src/main.c +++ b/src/main.c @@ -362,7 +362,19 @@ int main(int argc, char** argv) { printf("Are you sure? (Yes/[NO]): "); fflush(stdout); - if ((getchar()) != (int) 'Y') { + int character = getchar(); + if (character == EOF) { + if (ferror(stdin)) + PERROR_MACRO("getchar"); + else + ERROR_MSG("getchar", "End of file reached (STDIN)"); + + fclose(file); + + return EXIT_FAILURE; + } + + if (tolower(character) != 'y') { printf("File corruption aborted.\n"); return EXIT_FAILURE; }