diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-07 17:55:33 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-07 17:55:33 +0200 |
commit | 5711a2a4ad51ad203a2ed4ffc72593e83920b36a (patch) | |
tree | ef650852b982768fa9c3e4065016e09cbf2d0a96 /libbb | |
parent | c1e2e005b4e99070f58a3545bad54ef41a634ad1 (diff) | |
download | busybox-w32-5711a2a4ad51ad203a2ed4ffc72593e83920b36a.tar.gz busybox-w32-5711a2a4ad51ad203a2ed4ffc72593e83920b36a.tar.bz2 busybox-w32-5711a2a4ad51ad203a2ed4ffc72593e83920b36a.zip |
libbb: more compact API for bb_parse_mode()
function old new delta
make_device 2182 2188 +6
parse_command 1440 1443 +3
parse_params 1497 1499 +2
install_main 773 769 -4
mkdir_main 168 160 -8
getoptscmd 641 632 -9
builtin_umask 158 147 -11
bb_parse_mode 431 410 -21
umaskcmd 286 258 -28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/6 up/down: 11/-81) Total: -70 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/parse_mode.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/libbb/parse_mode.c b/libbb/parse_mode.c index 5a4e1c579..bddd39bca 100644 --- a/libbb/parse_mode.c +++ b/libbb/parse_mode.c | |||
@@ -15,7 +15,7 @@ | |||
15 | 15 | ||
16 | #define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) | 16 | #define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) |
17 | 17 | ||
18 | int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode) | 18 | int FAST_FUNC bb_parse_mode(const char *s, unsigned current_mode) |
19 | { | 19 | { |
20 | static const mode_t who_mask[] = { | 20 | static const mode_t who_mask[] = { |
21 | S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO, /* a */ | 21 | S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO, /* a */ |
@@ -46,13 +46,12 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode) | |||
46 | 46 | ||
47 | tmp = strtoul(s, &e, 8); | 47 | tmp = strtoul(s, &e, 8); |
48 | if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */ | 48 | if (*e || (tmp > 07777U)) { /* Check range and trailing chars. */ |
49 | return 0; | 49 | return -1; |
50 | } | 50 | } |
51 | *current_mode = tmp; | 51 | return tmp; |
52 | return 1; | ||
53 | } | 52 | } |
54 | 53 | ||
55 | new_mode = *current_mode; | 54 | new_mode = current_mode; |
56 | 55 | ||
57 | /* Note: we allow empty clauses, and hence empty modes. | 56 | /* Note: we allow empty clauses, and hence empty modes. |
58 | * We treat an empty mode as no change to perms. */ | 57 | * We treat an empty mode as no change to perms. */ |
@@ -71,7 +70,7 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode) | |||
71 | if (*p == *s) { | 70 | if (*p == *s) { |
72 | wholist |= who_mask[(int)(p-who_chars)]; | 71 | wholist |= who_mask[(int)(p-who_chars)]; |
73 | if (!*++s) { | 72 | if (!*++s) { |
74 | return 0; | 73 | return -1; |
75 | } | 74 | } |
76 | goto WHO_LIST; | 75 | goto WHO_LIST; |
77 | } | 76 | } |
@@ -80,7 +79,7 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode) | |||
80 | do { /* Process action list. */ | 79 | do { /* Process action list. */ |
81 | if ((*s != '+') && (*s != '-')) { | 80 | if ((*s != '+') && (*s != '-')) { |
82 | if (*s != '=') { | 81 | if (*s != '=') { |
83 | return 0; | 82 | return -1; |
84 | } | 83 | } |
85 | /* Since op is '=', clear all bits corresponding to the | 84 | /* Since op is '=', clear all bits corresponding to the |
86 | * wholist, or all file bits if wholist is empty. */ | 85 | * wholist, or all file bits if wholist is empty. */ |
@@ -145,6 +144,5 @@ int FAST_FUNC bb_parse_mode(const char *s, mode_t *current_mode) | |||
145 | } while (*s && (*s != ',')); | 144 | } while (*s && (*s != ',')); |
146 | } | 145 | } |
147 | 146 | ||
148 | *current_mode = new_mode; | 147 | return new_mode; |
149 | return 1; | ||
150 | } | 148 | } |