diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-10-06 02:36:47 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-10-06 02:36:47 +0200 |
commit | 2496616b0a8d1c80cd1416b73a4847b59b9f969a (patch) | |
tree | dc52a8f9bbbf33d507ecf0b808614b7923786567 | |
parent | 535a509846be5087ddd0d6e8fc6399f919942639 (diff) | |
download | busybox-w32-2496616b0a8d1c80cd1416b73a4847b59b9f969a.tar.gz busybox-w32-2496616b0a8d1c80cd1416b73a4847b59b9f969a.tar.bz2 busybox-w32-2496616b0a8d1c80cd1416b73a4847b59b9f969a.zip |
avoid using strok - eliminates use of hidden global variable
function old new delta
udhcp_str2optset 616 650 +34
setpriv_main 950 975 +25
switch_root_main 688 706 +18
parse 958 970 +12
getopt_main 622 628 +6
parse_resolvconf 302 306 +4
mpstat_main 1139 1142 +3
static.p 4 - -4
cdcmd 717 702 -15
strtok 148 - -148
------------------------------------------------------------------------------
(add/remove: 0/3 grow/shrink: 7/1 up/down: 102/-167) Total: -65 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | libbb/kernel_version.c | 20 | ||||
-rw-r--r-- | libbb/update_passwd.c | 15 | ||||
-rw-r--r-- | mailutils/reformime.c | 5 | ||||
-rw-r--r-- | networking/nslookup.c | 5 | ||||
-rw-r--r-- | networking/udhcp/common.c | 10 | ||||
-rw-r--r-- | procps/mpstat.c | 2 | ||||
-rw-r--r-- | shell/ash.c | 4 | ||||
-rw-r--r-- | util-linux/getopt.c | 5 | ||||
-rw-r--r-- | util-linux/mount.c | 3 | ||||
-rw-r--r-- | util-linux/setpriv.c | 9 | ||||
-rw-r--r-- | util-linux/switch_root.c | 4 |
11 files changed, 46 insertions, 36 deletions
diff --git a/libbb/kernel_version.c b/libbb/kernel_version.c index 7769a091b..6bb32ce5f 100644 --- a/libbb/kernel_version.c +++ b/libbb/kernel_version.c | |||
@@ -19,15 +19,17 @@ int FAST_FUNC get_linux_version_code(void) | |||
19 | { | 19 | { |
20 | struct utsname name; | 20 | struct utsname name; |
21 | char *t; | 21 | char *t; |
22 | int i, r; | 22 | int r; |
23 | 23 | ||
24 | uname(&name); /* never fails */ | 24 | uname(&name); /* never fails */ |
25 | t = name.release; | 25 | t = name.release - 1; |
26 | r = 0; | 26 | r = 1; |
27 | for (i = 0; i < 3; i++) { | 27 | do { |
28 | t = strtok(t, "."); | 28 | r <<= 8; |
29 | r = r * 256 + (t ? atoi(t) : 0); | 29 | if (t) { |
30 | t = NULL; | 30 | r += atoi(++t); |
31 | } | 31 | t = strchr(t, '.'); |
32 | return r; | 32 | } |
33 | } while (r < 0x1000000); | ||
34 | return r - 0x1000000; | ||
33 | } | 35 | } |
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c index c605c4c64..7b67f30cd 100644 --- a/libbb/update_passwd.c +++ b/libbb/update_passwd.c | |||
@@ -18,17 +18,20 @@ | |||
18 | #if ENABLE_SELINUX | 18 | #if ENABLE_SELINUX |
19 | static void check_selinux_update_passwd(const char *username) | 19 | static void check_selinux_update_passwd(const char *username) |
20 | { | 20 | { |
21 | security_context_t context; | 21 | security_context_t seuser; |
22 | char *seuser; | 22 | char *p; |
23 | 23 | ||
24 | if (getuid() != (uid_t)0 || is_selinux_enabled() == 0) | 24 | if (getuid() != (uid_t)0 || is_selinux_enabled() == 0) |
25 | return; /* No need to check */ | 25 | return; /* No need to check */ |
26 | 26 | ||
27 | if (getprevcon_raw(&context) < 0) | 27 | if (getprevcon_raw(&seuser) < 0) |
28 | bb_simple_perror_msg_and_die("getprevcon failed"); | 28 | bb_simple_perror_msg_and_die("getprevcon failed"); |
29 | seuser = strtok(context, ":"); | 29 | |
30 | if (!seuser) | 30 | p = strchr(seuser, ':'); |
31 | bb_error_msg_and_die("invalid context '%s'", context); | 31 | if (!p) |
32 | bb_error_msg_and_die("invalid context '%s'", seuser); | ||
33 | *p = '\0'; | ||
34 | |||
32 | if (strcmp(seuser, username) != 0) { | 35 | if (strcmp(seuser, username) != 0) { |
33 | security_class_t tclass; | 36 | security_class_t tclass; |
34 | access_vector_t av; | 37 | access_vector_t av; |
diff --git a/mailutils/reformime.c b/mailutils/reformime.c index 321729e0a..307656a15 100644 --- a/mailutils/reformime.c +++ b/mailutils/reformime.c | |||
@@ -115,6 +115,7 @@ static int parse(const char *boundary, char **argv) | |||
115 | /* Split to tokens */ | 115 | /* Split to tokens */ |
116 | { | 116 | { |
117 | char *s, *p; | 117 | char *s, *p; |
118 | char *tokstate; | ||
118 | unsigned ntokens; | 119 | unsigned ntokens; |
119 | const char *delims = ";=\" \t\n"; | 120 | const char *delims = ";=\" \t\n"; |
120 | 121 | ||
@@ -127,13 +128,13 @@ static int parse(const char *boundary, char **argv) | |||
127 | } | 128 | } |
128 | dbg_error_msg("L:'%s'", p); | 129 | dbg_error_msg("L:'%s'", p); |
129 | ntokens = 0; | 130 | ntokens = 0; |
130 | s = strtok(s, delims); | 131 | s = strtok_r(s, delims, &tokstate); |
131 | while (s) { | 132 | while (s) { |
132 | tokens[ntokens] = s; | 133 | tokens[ntokens] = s; |
133 | if (ntokens < ARRAY_SIZE(tokens) - 1) | 134 | if (ntokens < ARRAY_SIZE(tokens) - 1) |
134 | ntokens++; | 135 | ntokens++; |
135 | dbg_error_msg("L[%d]='%s'", ntokens, s); | 136 | dbg_error_msg("L[%d]='%s'", ntokens, s); |
136 | s = strtok(NULL, delims); | 137 | s = strtok_r(NULL, delims, &tokstate); |
137 | } | 138 | } |
138 | tokens[ntokens] = NULL; | 139 | tokens[ntokens] = NULL; |
139 | dbg_error_msg("EMPTYLINE, ntokens:%d", ntokens); | 140 | dbg_error_msg("EMPTYLINE, ntokens:%d", ntokens); |
diff --git a/networking/nslookup.c b/networking/nslookup.c index c43e60558..759de5c83 100644 --- a/networking/nslookup.c +++ b/networking/nslookup.c | |||
@@ -703,12 +703,13 @@ static void parse_resolvconf(void) | |||
703 | 703 | ||
704 | while (fgets(line, sizeof(line), resolv)) { | 704 | while (fgets(line, sizeof(line), resolv)) { |
705 | char *p, *arg; | 705 | char *p, *arg; |
706 | char *tokstate; | ||
706 | 707 | ||
707 | p = strtok(line, " \t\n"); | 708 | p = strtok_r(line, " \t\n", &tokstate); |
708 | if (!p) | 709 | if (!p) |
709 | continue; | 710 | continue; |
710 | dbg("resolv_key:'%s'\n", p); | 711 | dbg("resolv_key:'%s'\n", p); |
711 | arg = strtok(NULL, "\n"); | 712 | arg = strtok_r(NULL, "\n", &tokstate); |
712 | dbg("resolv_arg:'%s'\n", arg); | 713 | dbg("resolv_arg:'%s'\n", arg); |
713 | if (!arg) | 714 | if (!arg) |
714 | continue; | 715 | continue; |
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 20d843bab..4bc719001 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -526,7 +526,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, | |||
526 | 526 | ||
527 | /* Cheat, the only *const* str possible is "" */ | 527 | /* Cheat, the only *const* str possible is "" */ |
528 | str = (char *) const_str; | 528 | str = (char *) const_str; |
529 | opt = strtok(str, " \t=:"); | 529 | opt = strtok_r(str, " \t=:", &str); |
530 | if (!opt) | 530 | if (!opt) |
531 | return 0; | 531 | return 0; |
532 | 532 | ||
@@ -550,10 +550,10 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, | |||
550 | char *val; | 550 | char *val; |
551 | 551 | ||
552 | if (optflag->flags == OPTION_BIN) { | 552 | if (optflag->flags == OPTION_BIN) { |
553 | val = strtok(NULL, ""); /* do not split "'q w e'" */ | 553 | val = strtok_r(NULL, "", &str); /* do not split "'q w e'" */ |
554 | if (val) trim(val); | 554 | if (val) trim(val); |
555 | } else | 555 | } else |
556 | val = strtok(NULL, ", \t"); | 556 | val = strtok_r(NULL, ", \t", &str); |
557 | if (!val) | 557 | if (!val) |
558 | break; | 558 | break; |
559 | 559 | ||
@@ -567,7 +567,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, | |||
567 | break; | 567 | break; |
568 | case OPTION_IP_PAIR: | 568 | case OPTION_IP_PAIR: |
569 | retval = udhcp_str2nip(val, buffer); | 569 | retval = udhcp_str2nip(val, buffer); |
570 | val = strtok(NULL, ", \t/-"); | 570 | val = strtok_r(NULL, ", \t/-", &str); |
571 | if (!val) | 571 | if (!val) |
572 | retval = 0; | 572 | retval = 0; |
573 | if (retval) | 573 | if (retval) |
@@ -631,7 +631,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, | |||
631 | *slash = '\0'; | 631 | *slash = '\0'; |
632 | retval = udhcp_str2nip(val, buffer + 1); | 632 | retval = udhcp_str2nip(val, buffer + 1); |
633 | buffer[0] = mask = bb_strtou(slash + 1, NULL, 10); | 633 | buffer[0] = mask = bb_strtou(slash + 1, NULL, 10); |
634 | val = strtok(NULL, ", \t/-"); | 634 | val = strtok_r(NULL, ", \t/-", &str); |
635 | if (!val || mask > 32 || errno) | 635 | if (!val || mask > 32 || errno) |
636 | retval = 0; | 636 | retval = 0; |
637 | if (retval) { | 637 | if (retval) { |
diff --git a/procps/mpstat.c b/procps/mpstat.c index 52a436a55..c78c1f0a0 100644 --- a/procps/mpstat.c +++ b/procps/mpstat.c | |||
@@ -923,7 +923,7 @@ int mpstat_main(int argc UNUSED_PARAM, char **argv) | |||
923 | char *t; | 923 | char *t; |
924 | G.p_option = 1; | 924 | G.p_option = 1; |
925 | 925 | ||
926 | for (t = strtok(opt_set_cpu, ","); t; t = strtok(NULL, ",")) { | 926 | for (t = strtok_r(opt_set_cpu, ",", &opt_set_cpu); t; t = strtok_r(NULL, ",", &opt_set_cpu)) { |
927 | if (strcmp(t, "ALL") == 0) { | 927 | if (strcmp(t, "ALL") == 0) { |
928 | /* Select every CPU */ | 928 | /* Select every CPU */ |
929 | memset(G.cpu_bitmap, 0xff, G.cpu_bitmap_len); | 929 | memset(G.cpu_bitmap, 0xff, G.cpu_bitmap_len); |
diff --git a/shell/ash.c b/shell/ash.c index 07aa2da2e..58da0a2a0 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2770,7 +2770,7 @@ updatepwd(const char *dir) | |||
2770 | lim++; | 2770 | lim++; |
2771 | } | 2771 | } |
2772 | } | 2772 | } |
2773 | p = strtok(cdcomppath, "/"); | 2773 | p = strtok_r(cdcomppath, "/", &cdcomppath); |
2774 | while (p) { | 2774 | while (p) { |
2775 | switch (*p) { | 2775 | switch (*p) { |
2776 | case '.': | 2776 | case '.': |
@@ -2789,7 +2789,7 @@ updatepwd(const char *dir) | |||
2789 | new = stack_putstr(p, new); | 2789 | new = stack_putstr(p, new); |
2790 | USTPUTC('/', new); | 2790 | USTPUTC('/', new); |
2791 | } | 2791 | } |
2792 | p = strtok(NULL, "/"); | 2792 | p = strtok_r(NULL, "/", &cdcomppath); |
2793 | } | 2793 | } |
2794 | if (new > lim) | 2794 | if (new > lim) |
2795 | STUNPUTC(new); | 2795 | STUNPUTC(new); |
diff --git a/util-linux/getopt.c b/util-linux/getopt.c index db7db6ff8..1fa402429 100644 --- a/util-linux/getopt.c +++ b/util-linux/getopt.c | |||
@@ -289,12 +289,13 @@ static struct option *add_long_options(struct option *long_options, char *option | |||
289 | { | 289 | { |
290 | int long_nr = 0; | 290 | int long_nr = 0; |
291 | int arg_opt, tlen; | 291 | int arg_opt, tlen; |
292 | char *tokptr = strtok(options, ", \t\n"); | 292 | char *tokptr; |
293 | 293 | ||
294 | if (long_options) | 294 | if (long_options) |
295 | while (long_options[long_nr].name) | 295 | while (long_options[long_nr].name) |
296 | long_nr++; | 296 | long_nr++; |
297 | 297 | ||
298 | tokptr = strtok_r(options, ", \t\n", &options); | ||
298 | while (tokptr) { | 299 | while (tokptr) { |
299 | arg_opt = no_argument; | 300 | arg_opt = no_argument; |
300 | tlen = strlen(tokptr); | 301 | tlen = strlen(tokptr); |
@@ -318,7 +319,7 @@ static struct option *add_long_options(struct option *long_options, char *option | |||
318 | long_nr++; | 319 | long_nr++; |
319 | /*memset(&long_options[long_nr], 0, sizeof(long_options[0])); - xrealloc_vector did it */ | 320 | /*memset(&long_options[long_nr], 0, sizeof(long_options[0])); - xrealloc_vector did it */ |
320 | } | 321 | } |
321 | tokptr = strtok(NULL, ", \t\n"); | 322 | tokptr = strtok_r(NULL, ", \t\n", &options); |
322 | } | 323 | } |
323 | return long_options; | 324 | return long_options; |
324 | } | 325 | } |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 19ac13930..fc5161d7f 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -1230,6 +1230,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi | |||
1230 | * then data pointer is interpreted as a string. */ | 1230 | * then data pointer is interpreted as a string. */ |
1231 | struct nfs_mount_data data; | 1231 | struct nfs_mount_data data; |
1232 | char *opt; | 1232 | char *opt; |
1233 | char *tokstate; | ||
1233 | struct hostent *hp; | 1234 | struct hostent *hp; |
1234 | struct sockaddr_in server_addr; | 1235 | struct sockaddr_in server_addr; |
1235 | struct sockaddr_in mount_server_addr; | 1236 | struct sockaddr_in mount_server_addr; |
@@ -1348,7 +1349,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi | |||
1348 | nfsvers = 0; | 1349 | nfsvers = 0; |
1349 | 1350 | ||
1350 | /* parse options */ | 1351 | /* parse options */ |
1351 | if (filteropts) for (opt = strtok(filteropts, ","); opt; opt = strtok(NULL, ",")) { | 1352 | if (filteropts) for (opt = strtok_r(filteropts, ",", &tokstate); opt; opt = strtok_r(NULL, ",", &tokstate)) { |
1352 | char *opteq = strchr(opt, '='); | 1353 | char *opteq = strchr(opt, '='); |
1353 | if (opteq) { | 1354 | if (opteq) { |
1354 | int val, idx; | 1355 | int val, idx; |
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c index 37e8821a1..1e4b201ed 100644 --- a/util-linux/setpriv.c +++ b/util-linux/setpriv.c | |||
@@ -144,10 +144,11 @@ static unsigned parse_cap(const char *cap) | |||
144 | static void set_inh_caps(char *capstring) | 144 | static void set_inh_caps(char *capstring) |
145 | { | 145 | { |
146 | struct caps caps; | 146 | struct caps caps; |
147 | char *string; | ||
147 | 148 | ||
148 | getcaps(&caps); | 149 | getcaps(&caps); |
149 | 150 | ||
150 | capstring = strtok(capstring, ","); | 151 | capstring = strtok_r(capstring, ",", &string); |
151 | while (capstring) { | 152 | while (capstring) { |
152 | unsigned cap; | 153 | unsigned cap; |
153 | 154 | ||
@@ -159,7 +160,7 @@ static void set_inh_caps(char *capstring) | |||
159 | caps.data[CAP_TO_INDEX(cap)].inheritable |= CAP_TO_MASK(cap); | 160 | caps.data[CAP_TO_INDEX(cap)].inheritable |= CAP_TO_MASK(cap); |
160 | else | 161 | else |
161 | caps.data[CAP_TO_INDEX(cap)].inheritable &= ~CAP_TO_MASK(cap); | 162 | caps.data[CAP_TO_INDEX(cap)].inheritable &= ~CAP_TO_MASK(cap); |
162 | capstring = strtok(NULL, ","); | 163 | capstring = strtok_r(NULL, ",", &string); |
163 | } | 164 | } |
164 | 165 | ||
165 | if (capset(&caps.header, caps.data) != 0) | 166 | if (capset(&caps.header, caps.data) != 0) |
@@ -170,7 +171,7 @@ static void set_ambient_caps(char *string) | |||
170 | { | 171 | { |
171 | char *cap; | 172 | char *cap; |
172 | 173 | ||
173 | cap = strtok(string, ","); | 174 | cap = strtok_r(string, ",", &string); |
174 | while (cap) { | 175 | while (cap) { |
175 | unsigned idx; | 176 | unsigned idx; |
176 | 177 | ||
@@ -182,7 +183,7 @@ static void set_ambient_caps(char *string) | |||
182 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, idx, 0, 0) < 0) | 183 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_LOWER, idx, 0, 0) < 0) |
183 | bb_simple_perror_msg("cap_ambient_lower"); | 184 | bb_simple_perror_msg("cap_ambient_lower"); |
184 | } | 185 | } |
185 | cap = strtok(NULL, ","); | 186 | cap = strtok_r(NULL, ",", &string); |
186 | } | 187 | } |
187 | } | 188 | } |
188 | #endif /* FEATURE_SETPRIV_CAPABILITIES */ | 189 | #endif /* FEATURE_SETPRIV_CAPABILITIES */ |
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c index c65096c27..f2674b5ac 100644 --- a/util-linux/switch_root.c +++ b/util-linux/switch_root.c | |||
@@ -164,7 +164,7 @@ static void drop_capabilities(char *string) | |||
164 | { | 164 | { |
165 | char *cap; | 165 | char *cap; |
166 | 166 | ||
167 | cap = strtok(string, ","); | 167 | cap = strtok_r(string, ",", &string); |
168 | while (cap) { | 168 | while (cap) { |
169 | unsigned cap_idx; | 169 | unsigned cap_idx; |
170 | 170 | ||
@@ -174,7 +174,7 @@ static void drop_capabilities(char *string) | |||
174 | drop_bounding_set(cap_idx); | 174 | drop_bounding_set(cap_idx); |
175 | drop_capset(cap_idx); | 175 | drop_capset(cap_idx); |
176 | bb_error_msg("dropped capability: %s", cap); | 176 | bb_error_msg("dropped capability: %s", cap); |
177 | cap = strtok(NULL, ","); | 177 | cap = strtok_r(NULL, ",", &string); |
178 | } | 178 | } |
179 | } | 179 | } |
180 | #endif | 180 | #endif |