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 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 /* BB_AUDIT SUSv3 compliant */
14 /* BB_AUDIT GNU defects - unsupported options -c, -f, -v, and long options. */
15 /* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
24 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
26 if (!bb_parse_mode((char *)junk, &(statbuf->st_mode)))
27 bb_error_msg_and_die( "invalid mode: %s", (char *)junk);
28 if (chmod(fileName, statbuf->st_mode) == 0)
30 bb_perror_msg("%s", fileName); /* Avoid multibyte problems. */
34 int chmod_main(int ATTRIBUTE_UNUSED argc, char **argv)
36 int retval = EXIT_SUCCESS;
37 int recursiveFlag = FALSE;
47 for (p = argv ; *p ; p++) {
50 if ((p0[1] == '-') && !p0[2]) {
51 opt = 0; /* Disable further option processing. */
82 /* Ok, ready to do the deed now */
84 if (! recursive_action (*argv, recursiveFlag, TRUE, FALSE,
85 fileAction, fileAction, smode)) {
86 retval = EXIT_FAILURE;