diff options
author | mjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | mjn3 <mjn3@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-19 09:13:01 +0000 |
commit | e901c15d890dbbdce4c086963cb1513653fc46b5 (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/chgrp.c | |
parent | 40758c00616c3b2c85d83eb4afdeb04b1f65c9f1 (diff) | |
download | busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.gz busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.tar.bz2 busybox-w32-e901c15d890dbbdce4c086963cb1513653fc46b5.zip |
Major coreutils update.
git-svn-id: svn://busybox.net/trunk/busybox@6751 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/chgrp.c')
-rw-r--r-- | coreutils/chgrp.c | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c index 968b448c0..f5e5d29f1 100644 --- a/coreutils/chgrp.c +++ b/coreutils/chgrp.c | |||
@@ -21,9 +21,12 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <stdio.h> | 24 | /* BB_AUDIT SUSv3 defects - unsupported options -h, -H, -L, and -P. */ |
25 | /* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and long options. */ | ||
26 | /* BB_AUDIT Note: gnu chgrp does not support -H, -L, or -P. */ | ||
27 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */ | ||
28 | |||
25 | #include <stdlib.h> | 29 | #include <stdlib.h> |
26 | #include <string.h> | ||
27 | #include <unistd.h> | 30 | #include <unistd.h> |
28 | #include "busybox.h" | 31 | #include "busybox.h" |
29 | 32 | ||
@@ -32,53 +35,46 @@ | |||
32 | #define lchown chown | 35 | #define lchown chown |
33 | #endif | 36 | #endif |
34 | 37 | ||
35 | |||
36 | static long gid; | ||
37 | |||
38 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 38 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
39 | { | 39 | { |
40 | if (lchown(fileName, statbuf->st_uid, (gid == -1) ? statbuf->st_gid : gid) == 0) { | 40 | if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) { |
41 | return (TRUE); | 41 | return (TRUE); |
42 | } | 42 | } |
43 | perror(fileName); | 43 | bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */ |
44 | return (FALSE); | 44 | return (FALSE); |
45 | } | 45 | } |
46 | 46 | ||
47 | int chgrp_main(int argc, char **argv) | 47 | int chgrp_main(int argc, char **argv) |
48 | { | 48 | { |
49 | int opt; | 49 | long gid; |
50 | int recursiveFlag = FALSE; | 50 | int recursiveFlag;; |
51 | char *p=NULL; | 51 | int retval = EXIT_SUCCESS; |
52 | char *p; | ||
52 | 53 | ||
53 | /* do normal option parsing */ | 54 | recursiveFlag = bb_getopt_ulflags(argc, argv, "R"); |
54 | while ((opt = getopt(argc, argv, "R")) > 0) { | 55 | |
55 | switch (opt) { | 56 | if (argc - optind < 2) { |
56 | case 'R': | 57 | bb_show_usage(); |
57 | recursiveFlag = TRUE; | ||
58 | break; | ||
59 | default: | ||
60 | show_usage(); | ||
61 | } | ||
62 | } | 58 | } |
63 | 59 | ||
64 | if (argc > optind && argc > 2 && argv[optind]) { | 60 | argv += optind; |
65 | /* Find the selected group */ | 61 | |
66 | gid = strtoul(argv[optind], &p, 10); /* maybe it's already numeric */ | 62 | /* Find the selected group */ |
67 | if (argv[optind] == p) | 63 | gid = strtoul(*argv, &p, 10); /* maybe it's already numeric */ |
68 | gid = my_getgrnam(argv[optind]); | 64 | if (*p || (p == *argv)) { /* trailing chars or nonnumeric */ |
69 | } else { | 65 | gid = my_getgrnam(*argv); |
70 | error_msg_and_die(too_few_args); | ||
71 | } | 66 | } |
67 | ++argv; | ||
72 | 68 | ||
73 | /* Ok, ready to do the deed now */ | 69 | /* Ok, ready to do the deed now */ |
74 | while (++optind < argc) { | 70 | do { |
75 | if (! recursive_action (argv[optind], recursiveFlag, FALSE, FALSE, | 71 | if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, |
76 | fileAction, fileAction, NULL)) { | 72 | fileAction, fileAction, &gid)) { |
77 | return EXIT_FAILURE; | 73 | retval = EXIT_FAILURE; |
78 | } | 74 | } |
79 | } | 75 | } while (*++argv); |
80 | return EXIT_SUCCESS; | ||
81 | 76 | ||
77 | return retval; | ||
82 | } | 78 | } |
83 | 79 | ||
84 | /* | 80 | /* |