diff options
author | Karel Zak | 2011-01-05 16:50:47 +0100 |
---|---|---|
committer | Karel Zak | 2011-01-05 16:50:47 +0100 |
commit | 8feb31e5329da705e7fc99f7b28a261af8c9e493 (patch) | |
tree | 2a451fe65c88b17bbae6376724f194cdab9daea2 /fdisk/fdisk.c | |
parent | include: add fallback for rpmatch() (diff) | |
download | kernel-qcow2-util-linux-8feb31e5329da705e7fc99f7b28a261af8c9e493.tar.gz kernel-qcow2-util-linux-8feb31e5329da705e7fc99f7b28a261af8c9e493.tar.xz kernel-qcow2-util-linux-8feb31e5329da705e7fc99f7b28a261af8c9e493.zip |
fdisk: re-print prompt after maybe_exit()
after
Do you really want to quit? n
the read_chars() has to re-print the original prompt and ask again
for new input. For example:
Partition number (1-4, default 3): <-- CTRL-D
Do you really want to quit? n
Partition number (1-4, default 3): 3 <-- ask again
First sector (411648-1023999, default 411648):
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisk/fdisk.c')
-rw-r--r-- | fdisk/fdisk.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index 57e645d76..177fb14c6 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -1327,30 +1327,36 @@ static int is_partition_table_changed(void) return 0; } -static void maybe_exit(int rc) +static void maybe_exit(int rc, int *asked) { char line[LINE_LENGTH]; putchar('\n'); + if (asked) + *asked = 0; 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); + if (asked) + *asked = 1; } else exit(rc); } /* read line; return 0 or first char */ int -read_line(void) +read_line(int *asked) { line_ptr = line_buffer; if (!fgets(line_buffer, LINE_LENGTH, stdin)) { - maybe_exit(1); + maybe_exit(1, asked); return 0; } + if (asked) + *asked = 0; while (*line_ptr && !isgraph(*line_ptr)) line_ptr++; return *line_ptr; @@ -1362,16 +1368,22 @@ read_char(char *mesg) do { fputs(mesg, stdout); fflush (stdout); /* requested by niles@scyld.com */ - } while (!read_line()); + } while (!read_line(NULL)); return *line_ptr; } char read_chars(char *mesg) { - fputs(mesg, stdout); - fflush (stdout); /* niles@scyld.com */ - if (!read_line()) { + int rc, asked = 0; + + do { + fputs(mesg, stdout); + fflush (stdout); /* niles@scyld.com */ + rc = read_line(&asked); + } while (asked); + + if (!rc) { *line_ptr = '\n'; line_ptr[1] = 0; } |