source: MondoRescue/branches/stable/mindi-busybox/coreutils/chgrp.c@ 821

Last change on this file since 821 was 821, checked in by Bruno Cornec, 18 years ago

Addition of busybox 1.2.1 as a mindi-busybox new package
This should avoid delivering binary files in mindi not built there (Fedora and Debian are quite serious about that)

File size: 1.4 KB
RevLine 
[821]1/* vi: set sw=4 ts=4: */
2/*
3 * Mini chgrp implementation for busybox
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10/* BB_AUDIT SUSv3 defects - unsupported options -h, -H, -L, and -P. */
11/* BB_AUDIT GNU defects - unsupported options -h, -c, -f, -v, and long options. */
12/* BB_AUDIT Note: gnu chgrp does not support -H, -L, or -P. */
13/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
14
15#include <stdlib.h>
16#include <unistd.h>
17#include "busybox.h"
18
19/* Don't use lchown glibc older then 2.1.x */
20#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
21#define lchown chown
22#endif
23
24static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
25{
26 if (lchown(fileName, statbuf->st_uid, *((long *) junk)) == 0) {
27 return (TRUE);
28 }
29 bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
30 return (FALSE);
31}
32
33int chgrp_main(int argc, char **argv)
34{
35 long gid;
36 int recursiveFlag;
37 int retval = EXIT_SUCCESS;
38
39 recursiveFlag = bb_getopt_ulflags(argc, argv, "R");
40
41 if (argc - optind < 2) {
42 bb_show_usage();
43 }
44
45 argv += optind;
46
47 /* Find the selected group */
48 gid = get_ug_id(*argv, bb_xgetgrnam);
49 ++argv;
50
51 /* Ok, ready to do the deed now */
52 do {
53 if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
54 fileAction, fileAction, &gid)) {
55 retval = EXIT_FAILURE;
56 }
57 } while (*++argv);
58
59 return retval;
60}
Note: See TracBrowser for help on using the repository browser.