X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/77a8a873bf6678bc2c36a5839da714c5620683b6..11e2fb2dbbc074cce78d62fdf425e6bbf1918949:/sbr/getans.c diff --git a/sbr/getans.c b/sbr/getans.c index 682a3b14..0800a3c0 100644 --- a/sbr/getans.c +++ b/sbr/getans.c @@ -9,8 +9,7 @@ #include #include -#include -#include +#include static char ansbuf[BUFSIZ]; static sigjmp_buf sigenv; @@ -32,7 +31,6 @@ getans (char *prompt, struct swit *ansp) istat = SIGNAL (SIGINT, intrser); } else { SIGNAL (SIGINT, istat); - printf("returning NULL\n"); return NULL; } @@ -42,8 +40,34 @@ getans (char *prompt, struct swit *ansp) cp = ansbuf; while ((i = getchar ()) != '\n') { if (i == EOF) { - printf("Got EOF\n"); - siglongjmp (sigenv, 1); + /* + * If we get an EOF, return + */ + if (feof(stdin)) + siglongjmp (sigenv, 1); + + /* + * For errors, if we get an EINTR that means that we got + * a signal and we should retry. If we get another error, + * then just return. + */ + + else if (ferror(stdin)) { + if (errno == EINTR) { + clearerr(stdin); + continue; + } + fprintf(stderr, "\nError %s during read\n", + strerror(errno)); + siglongjmp (sigenv, 1); + } else { + /* + * Just for completeness's sake ... + */ + + fprintf(stderr, "\nUnknown problem in getchar()\n"); + siglongjmp (sigenv, 1); + } } if (cp < &ansbuf[sizeof ansbuf - 1]) *cp++ = i;