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
34 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
36 if (!parse_mode((char *)junk, &(statbuf->st_mode)))
37 error_msg_and_die( "unknown mode: %s", (char *)junk);
38 if (chmod(fileName, statbuf->st_mode) == 0)
44 int chmod_main(int argc, char **argv)
47 int recursiveFlag = FALSE;
48 int modeind = 0; /* Index of the mode argument in `argv'. */
50 static const char chmod_modes[] = "Rrwxstugoa,+-=";
52 /* do normal option parsing */
54 int thisind = optind ? optind : 1;
56 opt = getopt(argc, argv, chmod_modes);
59 smode = strchr(chmod_modes, opt);
62 if(smode == chmod_modes) { /* 'R' */
65 if (modeind != 0 && modeind != thisind)
76 error_msg_and_die(too_few_args);
79 smode = argv[modeind];
80 /* Ok, ready to do the deed now */
81 for (; opt < argc; opt++) {
82 if (! recursive_action (argv[opt], recursiveFlag, FALSE, FALSE, fileAction,