Making note of my changes
[oweals/busybox.git] / chmod_chown_chgrp.c
index e9704fff8b5df2158d889bbe30ebaab506a1bd89..75db904e866d094bc32f1099ccbd3c096dc84b55 100644 (file)
@@ -31,7 +31,7 @@ static uid_t uid=-1;
 static gid_t gid=-1;
 static int whichApp;
 static char* invocationName=NULL;
-static mode_t mode=0644;
+static char* theMode=NULL;
 
 
 #define CHGRP_APP   1
@@ -55,13 +55,18 @@ static int fileAction(const char *fileName, struct stat* statbuf)
     switch (whichApp) {
        case CHGRP_APP:
        case CHOWN_APP:
-           if (chown(fileName, (whichApp==CHOWN_APP)? uid : statbuf->st_uid, 
+           if (lchown(fileName, (whichApp==CHOWN_APP)? uid : statbuf->st_uid, 
                        (gid==-1)? statbuf->st_gid : gid) == 0) {
                return( TRUE);
            }
            break;
        case CHMOD_APP:
-           if (chmod(fileName, mode) == 0)
+           /* Parse the specified modes */
+           if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
+               fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
+               exit( FALSE);
+           }
+           if (chmod(fileName, statbuf->st_mode) == 0)
                return( TRUE);
            break;
     }
@@ -100,12 +105,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
     }
     
     if ( whichApp == CHMOD_APP ) {
-       /* Find the specified modes */
-       mode = 0;
-       if ( parse_mode(*argv, &mode) == FALSE ) {
-           fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv);
-           exit( FALSE);
-       }
+       theMode=*argv;
     } else {
 
        /* Find the selected group */