1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-12-27 07:30:23 +05:30

main.c: improve user prompt processing

This commit is contained in:
Intel A80486DX2-66 2024-11-18 18:44:23 +03:00
parent 1c25f705c0
commit 6776f0e989
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
2 changed files with 17 additions and 2 deletions

View File

@ -31,11 +31,14 @@ enum configurations {
fprintf(stream, __VA_ARGS__); \ fprintf(stream, __VA_ARGS__); \
} while (0) } while (0)
#define ERROR_MSG(a, b) \
fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, (a), (b))
#define PERROR_MACRO(s) do { \ #define PERROR_MACRO(s) do { \
int errnum = errno; \ int errnum = errno; \
char* err_msg = strerror(errnum); /* XXX: Thread race possible */ \ char* err_msg = strerror(errnum); /* XXX: Thread race possible */ \
fflush(stdout); \ fflush(stdout); \
fprintf(stderr, "%s:%d: %s: %s\n", __FILE__, __LINE__, (s), err_msg); \ ERROR_MSG((s), err_msg); \
} while (0) } while (0)
#define FATAL_ERROR_PRINT(...) do { \ #define FATAL_ERROR_PRINT(...) do { \

View File

@ -362,7 +362,19 @@ int main(int argc, char** argv) {
printf("Are you sure? (Yes/[NO]): "); printf("Are you sure? (Yes/[NO]): ");
fflush(stdout); 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"); printf("File corruption aborted.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }