diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-10-10 03:47:01 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-10-10 03:47:01 +0000 |
commit | d274b53c1d45aa829178c0aded9434f50a044a2f (patch) | |
tree | fa2c52531a04cb87c2963e64405b91dcb97bde88 | |
parent | 1bb1e83454a2177bad14a865b01532d3fceff89b (diff) | |
download | busybox-w32-d274b53c1d45aa829178c0aded9434f50a044a2f.tar.gz busybox-w32-d274b53c1d45aa829178c0aded9434f50a044a2f.tar.bz2 busybox-w32-d274b53c1d45aa829178c0aded9434f50a044a2f.zip |
last_patch59 from vodz to cleanup chmod and correctly parse '-rwxgoa'
-rw-r--r-- | coreutils/chmod.c | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/coreutils/chmod.c b/coreutils/chmod.c index 38b39680f..ba80e020a 100644 --- a/coreutils/chmod.c +++ b/coreutils/chmod.c | |||
@@ -5,6 +5,9 @@ | |||
5 | * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen | 5 | * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen |
6 | * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org> | 6 | * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org> |
7 | * | 7 | * |
8 | * Reworked by (C) 2002 Vladimir Oleynik <dzo@simtreas.ru> | ||
9 | * to correctly parse '-rwxgoa' | ||
10 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 12 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2 of the License, or | 13 | * the Free Software Foundation; either version 2 of the License, or |
@@ -31,7 +34,7 @@ | |||
31 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | 34 | static int fileAction(const char *fileName, struct stat *statbuf, void* junk) |
32 | { | 35 | { |
33 | if (!parse_mode((char *)junk, &(statbuf->st_mode))) | 36 | if (!parse_mode((char *)junk, &(statbuf->st_mode))) |
34 | error_msg_and_die("internal error"); | 37 | error_msg_and_die( "unknown mode: %s", (char *)junk); |
35 | if (chmod(fileName, statbuf->st_mode) == 0) | 38 | if (chmod(fileName, statbuf->st_mode) == 0) |
36 | return (TRUE); | 39 | return (TRUE); |
37 | perror(fileName); | 40 | perror(fileName); |
@@ -40,35 +43,44 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk) | |||
40 | 43 | ||
41 | int chmod_main(int argc, char **argv) | 44 | int chmod_main(int argc, char **argv) |
42 | { | 45 | { |
43 | int i; | ||
44 | int opt; | 46 | int opt; |
45 | int recursiveFlag = FALSE; | 47 | int recursiveFlag = FALSE; |
48 | int modeind = 0; /* Index of the mode argument in `argv'. */ | ||
49 | char *smode; | ||
50 | static const char chmod_modes[] = "Rrwxstugoa,+-="; | ||
46 | 51 | ||
47 | /* do normal option parsing */ | 52 | /* do normal option parsing */ |
48 | while ((opt = getopt(argc, argv, "R")) > 0) { | 53 | while (1) { |
49 | switch (opt) { | 54 | int thisind = optind ? optind : 1; |
50 | case 'R': | 55 | |
51 | recursiveFlag = TRUE; | 56 | opt = getopt(argc, argv, chmod_modes); |
57 | if (opt == EOF) | ||
52 | break; | 58 | break; |
53 | default: | 59 | smode = strchr(chmod_modes, opt); |
60 | if(smode == NULL) | ||
54 | show_usage(); | 61 | show_usage(); |
62 | if(smode == chmod_modes) { /* 'R' */ | ||
63 | recursiveFlag = TRUE; | ||
64 | } else { | ||
65 | if (modeind != 0 && modeind != thisind) | ||
66 | show_usage(); | ||
67 | modeind = thisind; | ||
55 | } | 68 | } |
56 | } | 69 | } |
57 | 70 | ||
58 | if (argc > optind && argc > 2 && argv[optind]) { | 71 | if (modeind == 0) |
59 | /* Parse the specified mode */ | 72 | modeind = optind++; |
60 | mode_t mode; | 73 | |
61 | if (! parse_mode(argv[optind], &mode)) { | 74 | opt = optind; |
62 | error_msg_and_die( "unknown mode: %s", argv[optind]); | 75 | if (opt >= argc) { |
63 | } | ||
64 | } else { | ||
65 | error_msg_and_die(too_few_args); | 76 | error_msg_and_die(too_few_args); |
66 | } | 77 | } |
67 | 78 | ||
79 | smode = argv[modeind]; | ||
68 | /* Ok, ready to do the deed now */ | 80 | /* Ok, ready to do the deed now */ |
69 | for (i = optind + 1; i < argc; i++) { | 81 | for (; opt < argc; opt++) { |
70 | if (! recursive_action (argv[i], recursiveFlag, FALSE, FALSE, fileAction, | 82 | if (! recursive_action (argv[opt], recursiveFlag, FALSE, FALSE, fileAction, |
71 | fileAction, argv[optind])) { | 83 | fileAction, smode)) { |
72 | return EXIT_FAILURE; | 84 | return EXIT_FAILURE; |
73 | } | 85 | } |
74 | } | 86 | } |