diff options
author | Francesco Cosoleto <cosoleto@gmail.com> | 2011-01-02 22:58:12 +0100 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2011-01-05 16:12:02 +0100 |
commit | aead9d139dc81db70a6a6d72c2163021a3656d74 (patch) | |
tree | c5dd65ba51482af256b77e14c578fa231633b400 /fdisk | |
parent | 1d9aaca90cb25e3f4c9fb8d1e9194232a3ff1544 (diff) | |
download | util-linux-old-aead9d139dc81db70a6a6d72c2163021a3656d74.tar.gz |
fdisk: quit with a single CTRL-D, confirm if necessary
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Diffstat (limited to 'fdisk')
-rw-r--r-- | fdisk/fdisk.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 5a694373..e1221aaa 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -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)) |