Prevent blocking on uiprompt error - sacc - sacc(omys), simple console gopher c… | |
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
LICENSE | |
--- | |
commit a3ee498a2796928b86bdb2b6fd73c56af68dc0eb | |
parent 199205cac2adb7d40a2ef7f4e20ad617e6437323 | |
Author: Quentin Rameau <[email protected]> | |
Date: Fri, 28 Jul 2017 23:18:00 +0200 | |
Prevent blocking on uiprompt error | |
Thanks to Hiltjo for reporting this! | |
Diffstat: | |
M ui_ti.c | 14 ++++++-------- | |
M ui_txt.c | 12 +++++------- | |
2 files changed, 11 insertions(+), 15 deletions(-) | |
--- | |
diff --git a/ui_ti.c b/ui_ti.c | |
@@ -81,14 +81,12 @@ uiprompt(char *fmt, ...) | |
putp(tparm(restore_cursor)); | |
fflush(stdout); | |
- if (r > 0) { | |
- if (input[r - 1] == '\n') | |
- input[--r] = '\0'; | |
- return input; | |
- } | |
- | |
- free(input); | |
- return NULL; | |
+ if (r < 0) | |
+ clearerr(stdin); | |
+ else if (input[r - 1] == '\n') | |
+ input[--r] = '\0'; | |
+ | |
+ return input; | |
} | |
static void | |
diff --git a/ui_txt.c b/ui_txt.c | |
@@ -83,14 +83,12 @@ uiprompt(char *fmt, ...) | |
fflush(stdout); | |
- if ((r = getline(&input, &n, stdin)) > 0) { | |
- if (input[r - 1] == '\n') | |
- input[--r] = '\0'; | |
- return input; | |
- } | |
+ if ((r = getline(&input, &n, stdin)) < 0) | |
+ clearerr(stdin); | |
+ else if (input[r - 1] == '\n') | |
+ input[--r] = '\0'; | |
- free(input); | |
- return NULL; | |
+ return input; | |
} | |
void |