Browse Source

rpmatch: use symbolic value when evaluation return codes

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
pull/154/head
Sami Kerola 8 years ago committed by Karel Zak
parent
commit
cd2a6f1cfd
  1. 2
      disk-utils/fdisk.c
  2. 6
      disk-utils/fsck.minix.c
  3. 2
      disk-utils/sfdisk.c
  4. 4
      include/rpmatch.h
  5. 2
      login-utils/vipw.c
  6. 6
      term-utils/mesg.c

2
disk-utils/fdisk.c

@ -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;
}

6
disk-utils/fsck.minix.c

@ -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:

2
disk-utils/sfdisk.c

@ -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;
}

4
include/rpmatch.h

@ -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 */

2
login-utils/vipw.c

@ -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);
}
}

6
term-utils/mesg.c

@ -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:

Loading…
Cancel
Save