summaryrefslogtreecommitdiff
path: root/functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'functions.c')
-rw-r--r--functions.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/functions.c b/functions.c
index cd56904..31282ed 100644
--- a/functions.c
+++ b/functions.c
@@ -132,8 +132,15 @@ void debugprint(int level, char *format, ...) {
va_end(args);
}
-// Get stdin line with buffer overrun protection
+// Get stdin line with buffer overrun protection.
+// Returns OK, NO_INPUT, or TOO_LONG as appropriate.
int getstdin(char *prompt, char *buff, size_t sz) {
+ if (prompt != NULL) {
+ debugprint(DEBUG_FULL, "getstdin(): '%s' (len %d), '%s' (len %d), size %zu.\n", prompt, strlen(prompt), buff, strlen(buff), sz);
+ } else {
+ debugprint(DEBUG_FULL, "getstdin(): '<null>' (len <null>), '%s' (len %d), size %zu.\n", buff, strlen(buff), sz);
+ }
+
int ch, extra;
// Print optional prompt
@@ -144,6 +151,11 @@ int getstdin(char *prompt, char *buff, size_t sz) {
// Get the intput from stdin
if (fgets (buff, sz, stdin) == NULL) {
+ if (feof(stdin)) {
+ debugprint(DEBUG_FULL, "getstdin(): Clearing EOF indicator on stdin.\n");
+ clearerr(stdin);
+ }
+
return NO_INPUT;
}