Browse Source

* fix our hand-made readline

master
Alex 'AdUser' Z 7 years ago
parent
commit
bce27da74f
  1. 11
      src/client.c

11
src/client.c

@ -96,9 +96,11 @@ signal_handler(int signum) {
char * char *
readline(const char *prompt) { readline(const char *prompt) {
char line[INPUT_LINE_MAX]; char line[INPUT_LINE_MAX];
char *p;
while (1) { while (1) {
line[0] = '\0'; line[0] = '\0';
p = &line[0];
fputs(prompt, stdout); fputs(prompt, stdout);
if (!fgets(line, sizeof(line) - 1, stdin)) { if (!fgets(line, sizeof(line) - 1, stdin)) {
if (feof(stdin)) { if (feof(stdin)) {
@ -106,12 +108,13 @@ readline(const char *prompt) {
} else { } else {
fputs("read error\n", stdout); fputs("read error\n", stdout);
} }
break; return NULL;
} }
if (line[0] == '\n') while (isspace(*p)) p++;
continue; if (*p != '\n' && *p != '\0')
return strdup(p);
} }
return strdup(line); return NULL;
} }
/* stubs */ /* stubs */

Loading…
Cancel
Save