summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-04-27 20:44:58 +0200
committerJim Meyering <meyering@redhat.com>2012-04-27 22:50:42 +0200
commita6719d9f7252bbd85eaab840a61dfc93d57b05c5 (patch)
tree1b42bb48a0dcbcd32f4c7d87903b70adc46addd5
parent032a549481444395558286b433296c97c09c721d (diff)
downloadcoreutils-a6719d9f7252bbd85eaab840a61dfc93d57b05c5.tar.xz
maint: id: minor factorization
* src/id.c (main): Factor out uses of "argc - optind". Move option-consistency checks to precede the potential getcon call.
-rw-r--r--src/id.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/id.c b/src/id.c
index c600e63d3..e1b51e764 100644
--- a/src/id.c
+++ b/src/id.c
@@ -163,34 +163,35 @@ main (int argc, char **argv)
}
}
- if (1 < argc - optind)
+ size_t n_ids = argc - optind;
+ if (1 < n_ids)
{
error (0, 0, _("extra operand %s"), quote (argv[optind + 1]));
usage (EXIT_FAILURE);
}
- if (argc - optind == 1 && just_context)
+ if (n_ids && just_context)
error (EXIT_FAILURE, 0,
_("cannot print security context when user specified"));
+ if (just_user + just_group + just_group_list + just_context > 1)
+ error (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice"));
+
+ if (just_user + just_group + just_group_list == 0 && (use_real || use_name))
+ error (EXIT_FAILURE, 0,
+ _("cannot print only names or real IDs in default format"));
+
/* If we are on a selinux-enabled kernel and no user is specified,
get our context. Otherwise, leave the context variable alone -
it has been initialized known invalid value and will be not
displayed in print_full_info() */
- if (selinux_enabled && argc == optind)
+ if (selinux_enabled && n_ids == 0)
{
if (getcon (&context) && just_context)
error (EXIT_FAILURE, 0, _("can't get process context"));
}
- if (just_user + just_group + just_group_list + just_context > 1)
- error (EXIT_FAILURE, 0, _("cannot print \"only\" of more than one choice"));
-
- if (just_user + just_group + just_group_list == 0 && (use_real || use_name))
- error (EXIT_FAILURE, 0,
- _("cannot print only names or real IDs in default format"));
-
- if (argc - optind == 1)
+ if (n_ids == 1)
{
struct passwd *pwd = getpwnam (argv[optind]);
if (pwd == NULL)