Fix uiprompt to return NULL on error (cancelation) - sacc - sacc(omys), simple console gopher client
(HTM) git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/sacc/
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) LICENSE
---
(DIR) commit c99d484c0e3619be44cb21f3b9f15d04a1e703c9
(DIR) parent 5fadc79985c013fe96490029054ef46299a4483a
(HTM) Author: Quentin Rameau <quinq@fifth.space>
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(-)
---
(DIR) 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;
}
(DIR) 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;
}