mirror of
https://git.disroot.org/80486DX2-66/polonium.git
synced 2024-12-25 23:00:07 +05:30
main.c: improve user prompt processing
This commit is contained in:
parent
1c25f705c0
commit
6776f0e989
@ -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 { \
|
||||
|
14
src/main.c
14
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user