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