diff options
-rw-r--r-- | sbin/restore/interactive.c | 11 | ||||
-rw-r--r-- | sbin/restore/tape.c | 16 | ||||
-rw-r--r-- | sbin/restore/utilities.c | 4 |
3 files changed, 16 insertions, 15 deletions
diff --git a/sbin/restore/interactive.c b/sbin/restore/interactive.c index ca0bc84..1fd8930 100644 --- a/sbin/restore/interactive.c +++ b/sbin/restore/interactive.c @@ -325,12 +325,11 @@ getcmd(curdir, cmd, name, size, ap) do { fprintf(stderr, "restore > "); (void) fflush(stderr); - (void) fgets(input, BUFSIZ, terminal); - } while (!feof(terminal) && input[0] == '\n'); - if (feof(terminal)) { - (void) strcpy(cmd, "quit"); - return; - } + if (fgets(input, BUFSIZ, terminal) == NULL) { + strcpy(cmd, "quit"); + return; + } + } while (input[0] == '\n'); for (cp = &input[strlen(input) - 2]; *cp == ' ' || *cp == '\t'; cp--) /* trim off trailing white space and newline */; *++cp = '\0'; diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c index 89b8b29..fdae506 100644 --- a/sbin/restore/tape.c +++ b/sbin/restore/tape.c @@ -307,8 +307,12 @@ getvol(nextvol) gettingfile = 0; } if (pipein) { - if (nextvol != 1) + if (nextvol != 1) { panic("Changing volumes on pipe input?\n"); + /* Avoid looping if we couldn't ask the user. */ + if (yflag || ferror(terminal) || feof(terminal)) + done(1); + } if (volno == 1) return; goto gethdr; @@ -345,10 +349,9 @@ again: do { fprintf(stderr, "Specify next volume #: "); (void) fflush(stderr); - (void) fgets(buf, BUFSIZ, terminal); - } while (!feof(terminal) && buf[0] == '\n'); - if (feof(terminal)) - done(1); + if (fgets(buf, BUFSIZ, terminal) == NULL) + done(1); + } while (buf[0] == '\n'); newvol = atoi(buf); if (newvol <= 0) { fprintf(stderr, @@ -364,8 +367,7 @@ again: fprintf(stderr, "Enter ``none'' if there are no more tapes\n"); fprintf(stderr, "otherwise enter tape name (default: %s) ", magtape); (void) fflush(stderr); - (void) fgets(buf, BUFSIZ, terminal); - if (feof(terminal)) + if (fgets(buf, BUFSIZ, terminal) == NULL) done(1); if (!strcmp(buf, "none\n")) { terminateinput(); diff --git a/sbin/restore/utilities.c b/sbin/restore/utilities.c index b51f90c..b7681f7 100644 --- a/sbin/restore/utilities.c +++ b/sbin/restore/utilities.c @@ -405,14 +405,14 @@ int reply(question) char *question; { - char c; + int c; do { fprintf(stderr, "%s? [yn] ", question); (void) fflush(stderr); c = getc(terminal); while (c != '\n' && getc(terminal) != '\n') - if (feof(terminal)) + if (c == EOF) return (FAIL); } while (c != 'y' && c != 'n'); if (c == 'y') |