summaryrefslogtreecommitdiffstats
path: root/fdisk/sfdisk.c
diff options
context:
space:
mode:
authorSami Kerola2012-02-29 00:27:04 +0100
committerSami Kerola2012-03-18 14:28:04 +0100
commit34ca51dcc7ce96e7131b110ed807df62f5216eb2 (patch)
treeb184c3c8fdb088bb95e524b6910b75154cede78f /fdisk/sfdisk.c
parentdocs: TODO removal, login-utils error printing (diff)
downloadkernel-qcow2-util-linux-34ca51dcc7ce96e7131b110ed807df62f5216eb2.tar.gz
kernel-qcow2-util-linux-34ca51dcc7ce96e7131b110ed807df62f5216eb2.tar.xz
kernel-qcow2-util-linux-34ca51dcc7ce96e7131b110ed807df62f5216eb2.zip
sfdisk: use rpmatch to yes/no question
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'fdisk/sfdisk.c')
-rw-r--r--fdisk/sfdisk.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/fdisk/sfdisk.c b/fdisk/sfdisk.c
index 6267652ff..f549c6413 100644
--- a/fdisk/sfdisk.c
+++ b/fdisk/sfdisk.c
@@ -53,6 +53,7 @@
#include "gpt.h"
#include "pathnames.h"
#include "canonicalize.h"
+#include "rpmatch.h"
/*
* Table of contents:
@@ -3140,7 +3141,7 @@ do_reread(char *dev) {
static void
do_fdisk(char *dev) {
int fd;
- int c, answer;
+ char answer[32];
struct stat statbuf;
int interactive = isatty(0);
struct disk_desc *z;
@@ -3197,22 +3198,20 @@ do_fdisk(char *dev) {
else
warnx(_("I don't like this - probably you should answer No\n"));
}
- ask:
if (interactive) {
+ ask:
if (no_write)
+ /* TRANSLATORS: sfdisk uses rpmatch which means the answers y and n
+ * should be translated, but that is not the case with q answer. */
printf(_("Are you satisfied with this? [ynq] "));
else
printf(_("Do you want to write this to disk? [ynq] "));
- answer = c = getchar();
- while (c != '\n' && c != EOF)
- c = getchar();
- if (c == EOF)
- printf(_("\nsfdisk: premature end of input\n"));
- if (c == EOF || answer == 'q' || answer == 'Q') {
+ fgets(answer, sizeof(answer), stdin);
+ if (answer[0] == 'q' || answer[0] == 'Q') {
errx(EXIT_FAILURE, _("Quitting - nothing changed"));
- } else if (answer == 'n' || answer == 'N') {
+ } else if (rpmatch(answer) == 1) {
continue;
- } else if (answer == 'y' || answer == 'Y') {
+ } else if (rpmatch(answer) == 0) {
break;
} else {
printf(_("Please answer one of y,n,q\n"));