1 /* vi: set sw=4 ts=4: */
3 * Mini chmod implementation for busybox
5 * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
6 * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
8 * Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru>
9 * to correctly parse '-rwxgoa'
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 /* BB_AUDIT SUSv3 compliant */
28 /* BB_AUDIT GNU defects - unsupported options -c, -f, -v, and long options. */
29 /* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
38 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
40 if (!bb_parse_mode((char *)junk, &(statbuf->st_mode)))
41 bb_error_msg_and_die( "invalid mode: %s", (char *)junk);
42 if (chmod(fileName, statbuf->st_mode) == 0)
44 bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
48 int chmod_main(int argc, char **argv)
50 int retval = EXIT_SUCCESS;
51 int recursiveFlag = FALSE;
61 for (p = argv ; *p ; p++) {
64 if ((p0[1] == '-') && !p0[2]) {
65 opt = 0; /* Disable further option processing. */
96 /* Ok, ready to do the deed now */
98 if (! recursive_action (*argv, recursiveFlag, FALSE, FALSE,
99 fileAction, fileAction, smode)) {
100 retval = EXIT_FAILURE;
109 c-file-style: "linux"