use bb_xbind/bb_xlisten
[oweals/busybox.git] / coreutils / chown.c
index 98f9d97882adddacc65f6e817b486aabf76be8c9..bb379ac205949898ecbc71acb81dff87e50750fa 100644 (file)
 #include <string.h>
 #include "busybox.h"
 
-static long uid;
-static long gid;
+static uid_t uid = -1;
+static gid_t gid = -1;
 
 static int (*chown_func)(const char *, uid_t, gid_t) = chown;
 
-static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
+static int fileAction(const char *fileName, struct stat *statbuf,
+               void ATTRIBUTE_UNUSED *junk)
 {
        if (!chown_func(fileName,
-                               (uid == -1) ? statbuf->st_uid : uid,
-                               (gid == -1) ? statbuf->st_gid : gid)) {
+                               (uid == (uid_t)-1) ? statbuf->st_uid : uid,
+                               (gid == (gid_t)-1) ? statbuf->st_gid : gid)) {
                return TRUE;
        }
        bb_perror_msg("%s", fileName);  /* A filename could have % in it... */
@@ -57,15 +58,12 @@ int chown_main(int argc, char **argv)
                groupName = strchr(*argv, ':');
        }
 
-       gid = -1;
+       /* Check for the username and groupname */
        if (groupName) {
                *groupName++ = '\0';
                gid = get_ug_id(groupName, bb_xgetgrnam);
        }
-
-       /* Now check for the username */
-       uid = get_ug_id(*argv, bb_xgetpwnam);
-
+       if (--groupName != *argv) uid = get_ug_id(*argv, bb_xgetpwnam);
        ++argv;
 
        /* Ok, ready to do the deed now */
@@ -78,11 +76,3 @@ int chown_main(int argc, char **argv)
 
        return retval;
 }
-
-/*
-Local Variables:
-c-file-style: "linux"
-c-basic-offset: 4
-tab-width: 4
-End:
-*/