summaryrefslogtreecommitdiffstats
path: root/fdisk
diff options
context:
space:
mode:
authorKarel Zak2011-01-05 16:50:47 +0100
committerKarel Zak2011-01-05 16:50:47 +0100
commit8feb31e5329da705e7fc99f7b28a261af8c9e493 (patch)
tree2a451fe65c88b17bbae6376724f194cdab9daea2 /fdisk
parentinclude: add fallback for rpmatch() (diff)
downloadkernel-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')
-rw-r--r--fdisk/fdisk.c26
-rw-r--r--fdisk/fdisk.h2
-rw-r--r--fdisk/fdiskbsdlabel.c4
3 files changed, 22 insertions, 10 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;
}
diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h
index 56230d685..612ab86b2 100644
--- a/fdisk/fdisk.h
+++ b/fdisk/fdisk.h
@@ -67,7 +67,7 @@ extern void get_geometry(int fd, struct geom *);
extern int get_boot(enum action what);
extern int get_partition(int warn, int max);
extern void list_types(struct systypes *sys);
-extern int read_line (void);
+extern int read_line (int *asked);
extern char read_char(char *mesg);
extern int read_hex(struct systypes *sys);
extern void reread_partition_table(int leave);
diff --git a/fdisk/fdiskbsdlabel.c b/fdisk/fdiskbsdlabel.c
index 9c0925242..0c3810d47 100644
--- a/fdisk/fdiskbsdlabel.c
+++ b/fdisk/fdiskbsdlabel.c
@@ -448,7 +448,7 @@ edit_int (int def, char *mesg)
do {
fputs (mesg, stdout);
printf (" (%d): ", def);
- if (!read_line ())
+ if (!read_line (NULL))
return def;
}
while (!isdigit (*line_ptr));
@@ -527,7 +527,7 @@ xbsd_write_bootstrap (void)
printf (_("Bootstrap: %sboot -> boot%s (%s): "),
dkbasename, dkbasename, dkbasename);
- if (read_line ()) {
+ if (read_line (NULL)) {
line_ptr[strlen (line_ptr)-1] = '\0';
dkbasename = line_ptr;
}