setpriv: code shrink
authorDenys Vlasenko <vda.linux@googlemail.com>
Sun, 20 Aug 2017 18:21:31 +0000 (20:21 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sun, 20 Aug 2017 18:21:31 +0000 (20:21 +0200)
function                                             old     new   delta
parse_cap                                            125     117      -8
setpriv_main                                         949     933     -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-24)             Total: -24 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
util-linux/setpriv.c

index 76fb62c223c2b1127c91df157d8fe248c6df236e..c549bcaf825b3bf29dde82ea134b292ca1cedc3c 100644 (file)
@@ -211,7 +211,7 @@ static void getcaps(struct caps *caps)
                bb_simple_perror_msg_and_die("capget");
 }
 
-static void parse_cap(unsigned long *index, const char *cap)
+static unsigned long parse_cap(const char *cap)
 {
        unsigned long i;
 
@@ -229,8 +229,7 @@ static void parse_cap(unsigned long *index, const char *cap)
        if ((sscanf(cap, "cap_%lu", &i)) == 1) {
                if (!cap_valid(i))
                        bb_error_msg_and_die("unsupported capability '%s'", cap);
-               *index = i;
-               return;
+               return i;
        }
 
 # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES
@@ -240,8 +239,7 @@ static void parse_cap(unsigned long *index, const char *cap)
 
                if (!cap_valid(i))
                        bb_error_msg_and_die("unsupported capability '%s'", cap);
-               *index = i;
-               return;
+               return i;
        }
 # endif
 
@@ -258,7 +256,7 @@ static void set_inh_caps(char *capstring)
        while (capstring) {
                unsigned long cap;
 
-               parse_cap(&cap, capstring);
+               cap = parse_cap(capstring);
                if (CAP_TO_INDEX(cap) >= caps.u32s)
                        bb_error_msg_and_die("invalid capability cap");
 
@@ -284,7 +282,7 @@ static void set_ambient_caps(char *string)
        while (cap) {
                unsigned long index;
 
-               parse_cap(&index, cap);
+               index = parse_cap(cap);
                if (cap[0] == '+') {
                        if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, index, 0, 0) < 0)
                                bb_perror_msg("cap_ambient_raise");
@@ -421,8 +419,8 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv)
        int opts;
        IF_FEATURE_SETPRIV_CAPABILITIES(char *inh_caps, *ambient_caps;)
 
-       opts = getopt32long(argv,
-               "+"IF_FEATURE_SETPRIV_DUMP("d")
+       opts = getopt32long(argv, "+"
+               IF_FEATURE_SETPRIV_DUMP("d")
                IF_FEATURE_SETPRIV_CAPABILITIES("\xfe:\xfd:"),
                setpriv_longopts
                IF_FEATURE_SETPRIV_CAPABILITIES(, &inh_caps, &ambient_caps)