rpmatch: use symbolic value when evaluation return codes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
parent
47d20536e0
commit
cd2a6f1cfd
|
@ -347,7 +347,7 @@ int ask_callback(struct fdisk_context *cxt, struct fdisk_ask *ask,
|
||||||
if (rc)
|
if (rc)
|
||||||
break;
|
break;
|
||||||
x = rpmatch(buf);
|
x = rpmatch(buf);
|
||||||
if (x == 1 || x == 0) {
|
if (x == RPMATCH_YES || x == RPMATCH_NO) {
|
||||||
fdisk_ask_yesno_set_result(ask, x);
|
fdisk_ask_yesno_set_result(ask, x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,11 +269,11 @@ ask(const char *string, int def) {
|
||||||
ignore_result( fgets(input, YESNO_LENGTH, stdin) );
|
ignore_result( fgets(input, YESNO_LENGTH, stdin) );
|
||||||
resp = rpmatch(input);
|
resp = rpmatch(input);
|
||||||
switch (resp) {
|
switch (resp) {
|
||||||
case -1:
|
case RPMATCH_INVALID:
|
||||||
/* def = def */
|
/* def = def */
|
||||||
break;
|
break;
|
||||||
case 0:
|
case RPMATCH_NO:
|
||||||
case 1:
|
case RPMATCH_YES:
|
||||||
def = resp;
|
def = resp;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -167,7 +167,7 @@ static int ask_callback(struct fdisk_context *cxt,
|
||||||
if (rc)
|
if (rc)
|
||||||
break;
|
break;
|
||||||
x = rpmatch(buf);
|
x = rpmatch(buf);
|
||||||
if (x == 1 || x == 0) {
|
if (x == RPMATCH_YES || x == RPMATCH_NO) {
|
||||||
fdisk_ask_yesno_set_result(ask, x);
|
fdisk_ask_yesno_set_result(ask, x);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,8 @@
|
||||||
(*r == 'y' || *r == 'Y' ? 1 : *r == 'n' || *r == 'N' ? 0 : -1)
|
(*r == 'y' || *r == 'Y' ? 1 : *r == 'n' || *r == 'N' ? 0 : -1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define RPMATCH_YES 1
|
||||||
|
#define RPMATCH_NO 0
|
||||||
|
#define RPMATCH_INVALID -1
|
||||||
|
|
||||||
#endif /* UTIL_LINUX_RPMATCH_H */
|
#endif /* UTIL_LINUX_RPMATCH_H */
|
||||||
|
|
|
@ -352,7 +352,7 @@ int main(int argc, char *argv[])
|
||||||
printf(_("Would you like to edit %s now [y/n]? "), orig_file);
|
printf(_("Would you like to edit %s now [y/n]? "), orig_file);
|
||||||
|
|
||||||
if (fgets(response, sizeof(response), stdin)) {
|
if (fgets(response, sizeof(response), stdin)) {
|
||||||
if (rpmatch(response) == 1)
|
if (rpmatch(response) == RPMATCH_YES)
|
||||||
edit_file(1);
|
edit_file(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (rpmatch(argv[0])) {
|
switch (rpmatch(argv[0])) {
|
||||||
case 1:
|
case RPMATCH_YES:
|
||||||
#ifdef USE_TTY_GROUP
|
#ifdef USE_TTY_GROUP
|
||||||
if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
|
if (chmod(tty, sb.st_mode | S_IWGRP) < 0)
|
||||||
#else
|
#else
|
||||||
|
@ -147,13 +147,13 @@ int main(int argc, char *argv[])
|
||||||
if (verbose)
|
if (verbose)
|
||||||
puts(_("write access to your terminal is allowed"));
|
puts(_("write access to your terminal is allowed"));
|
||||||
return IS_ALLOWED;
|
return IS_ALLOWED;
|
||||||
case 0:
|
case RPMATCH_NO:
|
||||||
if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0)
|
if (chmod(tty, sb.st_mode & ~(S_IWGRP|S_IWOTH)) < 0)
|
||||||
err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
|
err(MESG_EXIT_FAILURE, _("change %s mode failed"), tty);
|
||||||
if (verbose)
|
if (verbose)
|
||||||
puts(_("write access to your terminal is denied"));
|
puts(_("write access to your terminal is denied"));
|
||||||
return IS_NOT_ALLOWED;
|
return IS_NOT_ALLOWED;
|
||||||
case -1:
|
case RPMATCH_INVALID:
|
||||||
warnx(_("invalid argument: %s"), argv[0]);
|
warnx(_("invalid argument: %s"), argv[0]);
|
||||||
usage(stderr);
|
usage(stderr);
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue