summaryrefslogtreecommitdiff
path: root/src/chgrp.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-07-28 23:36:59 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-07-28 23:36:59 +0000
commita830ae0cbb20ae106d267bb458b08e8189e70840 (patch)
tree6168e9e4c8590fefe10f428b22075c51ba9487a5 /src/chgrp.c
parent3badaccae1d47fc7265dd66edc8c707f23607320 (diff)
downloadcoreutils-a830ae0cbb20ae106d267bb458b08e8189e70840.tar.xz
(parse_group): Require base 10 when parsing groups as integers.
(main): int -> bool when appropriate.
Diffstat (limited to 'src/chgrp.c')
-rw-r--r--src/chgrp.c25
1 files changed, 8 insertions, 17 deletions
diff --git a/src/chgrp.c b/src/chgrp.c
index 6cc22cf7a..a862c516d 100644
--- a/src/chgrp.c
+++ b/src/chgrp.c
@@ -88,19 +88,10 @@ parse_group (const char *name, gid_t *g)
grp = getgrnam (name);
if (grp == NULL)
{
- strtol_error s_err;
unsigned long int tmp_long;
-
- if (!ISDIGIT (*name))
- error (EXIT_FAILURE, 0, _("invalid group name %s"), quote (name));
-
- s_err = xstrtoul (name, NULL, 0, &tmp_long, NULL);
- if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (name, _("group number"), s_err);
-
- if (tmp_long > GID_T_MAX)
- error (EXIT_FAILURE, 0, _("invalid group number %s"), quote (name));
-
+ if (! (xstrtoul (name, NULL, 10, &tmp_long, "") == LONGINT_OK
+ && tmp_long <= GID_T_MAX))
+ error (EXIT_FAILURE, 0, _("invalid group %s"), quote (name));
*g = tmp_long;
}
else
@@ -178,7 +169,7 @@ main (int argc, char **argv)
int dereference = -1;
struct Chown_option chopt;
- int fail;
+ bool ok;
int optc;
initialize_main (&argc, &argv);
@@ -294,11 +285,11 @@ main (int argc, char **argv)
parse_group (chopt.group_name, &gid);
}
- fail = chown_files (argv + optind, bit_flags,
- (uid_t) -1, gid,
- (uid_t) -1, (gid_t) -1, &chopt);
+ ok = chown_files (argv + optind, bit_flags,
+ (uid_t) -1, gid,
+ (uid_t) -1, (gid_t) -1, &chopt);
chopt_free (&chopt);
- exit (fail ? EXIT_FAILURE : EXIT_SUCCESS);
+ exit (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}