]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rpmatch: use symbolic value when evaluation return codes
authorSami Kerola <kerolasa@iki.fi>
Sun, 22 Feb 2015 14:41:40 +0000 (14:41 +0000)
committerKarel Zak <kzak@redhat.com>
Tue, 24 Feb 2015 11:42:06 +0000 (12:42 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
disk-utils/fdisk.c
disk-utils/fsck.minix.c
disk-utils/sfdisk.c
include/rpmatch.h
login-utils/vipw.c
term-utils/mesg.c

index 8a0bfd575d1a6c0de9fff6d01d102170a9edc1ac..815f3f3eb0391c225ef1c813cccf6efccd2c8f61 100644 (file)
@@ -347,7 +347,7 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
                        if (rc)
                                break;
                        x = rpmatch(buf);
-                       if (x == 1 || x == 0) {
+                       if (x == RPMATCH_YES || x == RPMATCH_NO) {
                                fdisk_ask_yesno_set_result(ask, x);
                                break;
                        }
index ac2dc47fd1bcc7cccb21e822e0d35021497f3005..52b001b475de5d46b79cccb4645758e10ba980ea 100644 (file)
@@ -269,11 +269,11 @@ ask(const char *string, int def) {
        ignore_result( fgets(input, YESNO_LENGTH, stdin) );
        resp = rpmatch(input);
        switch (resp) {
-       case -1:
+       case RPMATCH_INVALID:
                /* def = def */
                break;
-       case 0:
-       case 1:
+       case RPMATCH_NO:
+       case RPMATCH_YES:
                def = resp;
                break;
        default:
index b7d448005657a8fbb6723eba7636371665124327..bce94e5044c81e2aa8fd1479ed54dfd27fb31c37 100644 (file)
@@ -167,7 +167,7 @@ static int ask_callback(struct fdisk_context *cxt,
                        if (rc)
                                break;
                        x = rpmatch(buf);
-                       if (x == 1 || x == 0) {
+                       if (x == RPMATCH_YES || x == RPMATCH_NO) {
                                fdisk_ask_yesno_set_result(ask, x);
                                break;
                        }
index d62634bd89030e80682c7dea513ecb9d750f4357..f64d52e16355ab5bd6643d8631802b52d6180304 100644 (file)
@@ -6,4 +6,8 @@
        (*r == 'y' || *r == 'Y' ? 1 : *r == 'n' || *r == 'N' ? 0 : -1)
 #endif
 
+#define RPMATCH_YES     1
+#define RPMATCH_NO      0
+#define RPMATCH_INVALID        -1
+
 #endif /* UTIL_LINUX_RPMATCH_H */
index 668f4d8c4a4651b743e17bb776f70e70d998131c..9fb25502c9a8392d13998238b45d00e980e32d49 100644 (file)
@@ -352,7 +352,7 @@ int main(int argc, char *argv[])
                printf(_("Would you like to edit %s now [y/n]? "), orig_file);
 
                if (fgets(response, sizeof(response), stdin)) {
-                       if (rpmatch(response) == 1)
+                       if (rpmatch(response) == RPMATCH_YES)
                                edit_file(1);
                }
        }
index 3cb1d24e6dfcc0169cdd8baba3064a1f8d2a591d..77d89c755ec77c4e8e038118ffbfef1c97924c77 100644 (file)
@@ -137,7 +137,7 @@ int main(int argc, char *argv[])
        }
 
        switch (rpmatch(argv[0])) {
-       case 1:
+       case RPMATCH_YES:
 #ifdef USE_TTY_GROUP
                if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
 #else
@@ -147,13 +147,13 @@ int main(int argc, char *argv[])
                if (verbose)
                        puts(_("write access to your terminal is allowed"));
                return IS_ALLOWED;
-       case 0:
+       case RPMATCH_NO:
                if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0)
                         err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
                if (verbose)
                        puts(_("write access to your terminal is denied"));
                return IS_NOT_ALLOWED;
-        case -1:
+       case RPMATCH_INVALID:
                warnx(_("invalid argument: %s"), argv[0]);
                usage(stderr);
         default: