Fix uiprompt to return NULL on error (cancelation) - sacc - sacc(omys), simple … | |
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65… | |
Log | |
Files | |
Refs | |
Tags | |
LICENSE | |
--- | |
commit c99d484c0e3619be44cb21f3b9f15d04a1e703c9 | |
parent 5fadc79985c013fe96490029054ef46299a4483a | |
Author: Quentin Rameau <[email protected]> | |
Date: Thu, 31 Aug 2017 18:31:52 +0200 | |
Fix uiprompt to return NULL on error (cancelation) | |
Thanks to solene for spotting this! | |
Diffstat: | |
M ui_ti.c | 6 ++++-- | |
M ui_txt.c | 7 +++++-- | |
2 files changed, 9 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/ui_ti.c b/ui_ti.c | |
@@ -74,10 +74,12 @@ uiprompt(char *fmt, ...) | |
putp(tparm(restore_cursor)); | |
fflush(stdout); | |
- if (r < 0) | |
+ if (r < 0) { | |
clearerr(stdin); | |
- else if (input[r - 1] == '\n') | |
+ clear(&input); | |
+ } else if (input[r - 1] == '\n') { | |
input[--r] = '\0'; | |
+ } | |
return input; | |
} | |
diff --git a/ui_txt.c b/ui_txt.c | |
@@ -99,10 +99,13 @@ uiprompt(char *fmt, ...) | |
fflush(stdout); | |
- if ((r = getline(&input, &n, stdin)) < 0) | |
+ if ((r = getline(&input, &n, stdin)) < 0) { | |
clearerr(stdin); | |
- else if (input[r - 1] == '\n') | |
+ clear(&input); | |
+ putchar('\n'); | |
+ } else if (input[r - 1] == '\n') { | |
input[--r] = '\0'; | |
+ } | |
return input; | |
} |