From bce27da74f40ad3d1432d2f97c097052cc742ecd Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Fri, 28 Apr 2017 11:50:04 +1000 Subject: [PATCH] * fix our hand-made readline --- src/client.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/client.c b/src/client.c index 4215280..7e47cc9 100644 --- a/src/client.c +++ b/src/client.c @@ -96,9 +96,11 @@ signal_handler(int signum) { char * readline(const char *prompt) { char line[INPUT_LINE_MAX]; + char *p; while (1) { line[0] = '\0'; + p = &line[0]; fputs(prompt, stdout); if (!fgets(line, sizeof(line) - 1, stdin)) { if (feof(stdin)) { @@ -106,12 +108,13 @@ readline(const char *prompt) { } else { fputs("read error\n", stdout); } - break; + return NULL; } - if (line[0] == '\n') - continue; + while (isspace(*p)) p++; + if (*p != '\n' && *p != '\0') + return strdup(p); } - return strdup(line); + return NULL; } /* stubs */