]> err.no Git - util-linux/commitdiff
fdisk: quit with a single CTRL-D, confirm if necessary
authorFrancesco Cosoleto <cosoleto@gmail.com>
Sun, 2 Jan 2011 21:58:12 +0000 (22:58 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 5 Jan 2011 15:12:02 +0000 (16:12 +0100)
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
fdisk/fdisk.c

index 5a69437393e5a549b37e01ee111a4c865b4a77f1..e1221aaa5e8b10c622adb90afa3c79cc308fbcf8 100644 (file)
@@ -1316,21 +1316,38 @@ got_dos_table:
        return 0;
 }
 
+static int is_partition_table_changed(void)
+{
+       int i;
+
+       for (i = 0; i < partitions; i++)
+               if (ptes[i].changed)
+                       return 1;
+       return 0;
+}
+
+static void maybe_exit(int rc)
+{
+       char line[LINE_LENGTH];
+
+       putchar('\n');
+
+       if (is_partition_table_changed() || MBRbuffer_changed) {
+               fprintf(stderr, _("Do you really want to quit? "));
+
+               if (!fgets(line, LINE_LENGTH, stdin) || rpmatch(line) == 1)
+                       exit(rc);
+       } else
+               exit(rc);
+}
+
 /* read line; return 0 or first char */
 int
 read_line(void)
 {
-       static int got_eof = 0;
-
        line_ptr = line_buffer;
        if (!fgets(line_buffer, LINE_LENGTH, stdin)) {
-               if (feof(stdin))
-                       got_eof++;      /* user typed ^D ? */
-               if (got_eof >= 3) {
-                       fflush(stdout);
-                       fprintf(stderr, _("\ngot EOF thrice - exiting..\n"));
-                       exit(1);
-               }
+               maybe_exit(1);
                return 0;
        }
        while (*line_ptr && !isgraph(*line_ptr))