X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=coreutils%2Fchgrp.c;h=8cfb54241b2cb994a67df57bddca69f45407e5dc;hb=0fb397e6176bebd31d27f8b2105b808091207366;hp=83bb194635da11a22f64d958a7af2cb772a475c8;hpb=30592a54514ca52253ed5f2eff64684e32d7ff05;p=oweals%2Fbusybox.git diff --git a/coreutils/chgrp.c b/coreutils/chgrp.c index 83bb19463..8cfb54241 100644 --- a/coreutils/chgrp.c +++ b/coreutils/chgrp.c @@ -1,10 +1,8 @@ /* vi: set sw=4 ts=4: */ /* - * Mini chown/chmod/chgrp implementation for busybox + * Mini chgrp implementation for busybox * - * - * Copyright (C) 1999,2000,2001 by Lineo, inc. - * Written by Erik Andersen , + * Copyright (C) 1999-2004 by Erik Andersen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,63 +20,56 @@ * */ -#include +/* 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 -#include #include #include "busybox.h" -/* Don't use lchown for libc5 or glibc older then 2.1.x */ +/* Don't use lchown glibc older then 2.1.x */ #if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1) #define lchown chown #endif - -static long gid = -1; - 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; - /* do normal option parsing */ - while ((opt = getopt(argc, argv, "R")) > 0) { - switch (opt) { - case 'R': - recursiveFlag = TRUE; - default: - show_usage(); - } - } + recursiveFlag = bb_getopt_ulflags(argc, argv, "R"); - 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); + if (argc - optind < 2) { + bb_show_usage(); } + argv += optind; + + /* Find the selected group */ + gid = get_ug_id(*argv, my_getgrnam); + ++argv; + /* Ok, ready to do the deed now */ - while (optind++ < argc-1) { - if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE, - fileAction, fileAction, NULL) == FALSE) { - return EXIT_FAILURE; + do { + if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE, + fileAction, fileAction, &gid)) { + retval = EXIT_FAILURE; } - } - return EXIT_SUCCESS; + } while (*++argv); + return retval; } /*