summaryrefslogtreecommitdiff
path: root/coreutils/chgrp.c
diff options
context:
space:
mode:
authorManuel Novoa III2003-03-19 09:13:01 +0000
committerManuel Novoa III2003-03-19 09:13:01 +0000
commitcad5364599eb5062d59e0c397ed638ddd61a8d5d (patch)
treea318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/chgrp.c
parente01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff)
downloadbusybox-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip
busybox-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz
Major coreutils update.
Diffstat (limited to 'coreutils/chgrp.c')
-rw-r--r--coreutils/chgrp.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c
index 968b448..f5e5d29 100644
--- a/coreutils/chgrp.c
+++ b/coreutils/chgrp.c
@@ -21,9 +21,12 @@
*
*/
-#include <stdio.h>
+/* BB_AUDIT SUSv3 defects - unsupported options -h, -H, -L, and -P. */
+/* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and long options. */
+/* BB_AUDIT Note: gnu chgrp does not support -H, -L, or -P. */
+/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
+
#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
#include "busybox.h"
@@ -32,53 +35,46 @@
#define lchown chown
#endif
-
-static long gid;
-
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
- if (lchown(fileName, statbuf->st_uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
+ if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) {
return (TRUE);
}
- perror(fileName);
+ bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
return (FALSE);
}
int chgrp_main(int argc, char **argv)
{
- int opt;
- int recursiveFlag = FALSE;
- char *p=NULL;
+ long gid;
+ int recursiveFlag;;
+ int retval = EXIT_SUCCESS;
+ char *p;
- /* do normal option parsing */
- while ((opt = getopt(argc, argv, "R")) > 0) {
- switch (opt) {
- case 'R':
- recursiveFlag = TRUE;
- break;
- default:
- show_usage();
- }
+ recursiveFlag = bb_getopt_ulflags(argc, argv, "R");
+
+ if (argc - optind < 2) {
+ bb_show_usage();
}
- if (argc > optind && argc > 2 && argv[optind]) {
- /* Find the selected group */
- gid = strtoul(argv[optind], &p, 10); /* maybe it's already numeric */
- if (argv[optind] == p)
- gid = my_getgrnam(argv[optind]);
- } else {
- error_msg_and_die(too_few_args);
+ argv += optind;
+
+ /* Find the selected group */
+ gid = strtoul(*argv, &p, 10); /* maybe it's already numeric */
+ if (*p || (p == *argv)) { /* trailing chars or nonnumeric */
+ gid = my_getgrnam(*argv);
}
+ ++argv;
/* Ok, ready to do the deed now */
- while (++optind < argc) {
- if (! recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
- fileAction, fileAction, NULL)) {
- return EXIT_FAILURE;
+ do {
+ if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
+ fileAction, fileAction, &gid)) {
+ retval = EXIT_FAILURE;
}
- }
- return EXIT_SUCCESS;
+ } while (*++argv);
+ return retval;
}
/*