]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix confirmation prompt
authorYann Collet <yann.collet.73@gmail.com>
Tue, 29 Dec 2015 10:57:15 +0000 (11:57 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 29 Dec 2015 10:57:15 +0000 (11:57 +0100)
programs/fileio.c

index 3867301a99577a46803e100b222427b3d020a8b7..0d49af2b9f3f451726829dc25a8033bdf7218d65 100644 (file)
@@ -225,7 +225,6 @@ static int FIO_getFiles(FILE** fileOutPtr, FILE** fileInPtr,
             if (*fileOutPtr != 0)
             {
                 /* prompt for overwrite authorization */
-                int ch = 'N';
                 fclose(*fileOutPtr);
                 DISPLAY("Warning : %s already exists \n", dstFileName);
                 if ((g_displayLevel <= 1) || (*fileInPtr == stdin))
@@ -235,11 +234,14 @@ static int FIO_getFiles(FILE** fileOutPtr, FILE** fileInPtr,
                     return 1;
                 }
                 DISPLAY("Overwrite ? (y/N) : ");
-                while((ch = getchar()) != '\n' && ch != EOF);   /* flush integrated */
-                if ((ch!='Y') && (ch!='y'))
                 {
-                    DISPLAY("No. Operation aborted : %s already exists \n", dstFileName);
-                    return 1;
+                    int ch = getchar();
+                    if ((ch!='Y') && (ch!='y'))
+                    {
+                        DISPLAY("No. Operation aborted : %s already exists \n", dstFileName);
+                        return 1;
+                    }
+                    while ((ch!=EOF) && (ch!='\n')) ch = getchar();  /* flush rest of input line */
                 }
             }
         }