diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-04 08:56:04 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-04 08:56:04 +0000 |
commit | 31997b1796bdaf5734f5fff1a20a637d8872419d (patch) | |
tree | 9c27f6741a1149059cb4f2cb324f6b2ee913e428 /win32/process.c | |
parent | 13cb88b0f6f2a69076e91858fbbdd0c65697e621 (diff) | |
download | busybox-w32-31997b1796bdaf5734f5fff1a20a637d8872419d.tar.gz busybox-w32-31997b1796bdaf5734f5fff1a20a637d8872419d.tar.bz2 busybox-w32-31997b1796bdaf5734f5fff1a20a637d8872419d.zip |
win32: reduce amount of static data
It appears that uninitialised static variables are placed in the
data section rather than bss, increasing the size of the binary.
Rewrite some code to reduce the amount of static data.
Diffstat (limited to '')
-rw-r--r-- | win32/process.c | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/win32/process.c b/win32/process.c index 96561c482..0d6d70970 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -39,43 +39,50 @@ next_path_sep(const char *path) | |||
39 | return strchr(has_dos_drive_prefix(path) ? path+2 : path, ':'); | 39 | return strchr(has_dos_drive_prefix(path) ? path+2 : path, ':'); |
40 | } | 40 | } |
41 | 41 | ||
42 | static char * | 42 | typedef struct { |
43 | parse_interpreter(const char *cmd, char **name, char **opts) | 43 | char *path; |
44 | char *name; | ||
45 | char *opts; | ||
46 | char buf[100]; | ||
47 | } interp_t; | ||
48 | |||
49 | static int | ||
50 | parse_interpreter(const char *cmd, interp_t *interp) | ||
44 | { | 51 | { |
45 | static char buf[100]; | ||
46 | char *path, *t; | 52 | char *path, *t; |
47 | int n, fd; | 53 | int n, fd; |
48 | 54 | ||
49 | fd = open(cmd, O_RDONLY); | 55 | fd = open(cmd, O_RDONLY); |
50 | if (fd < 0) | 56 | if (fd < 0) |
51 | return NULL; | 57 | return 0; |
52 | n = read(fd, buf, sizeof(buf)-1); | 58 | n = read(fd, interp->buf, sizeof(interp->buf)-1); |
53 | close(fd); | 59 | close(fd); |
54 | if (n < 4) /* at least '#!/x' and not error */ | 60 | if (n < 4) /* at least '#!/x' and not error */ |
55 | return NULL; | 61 | return 0; |
56 | 62 | ||
57 | /* | 63 | /* |
58 | * See http://www.in-ulm.de/~mascheck/various/shebang/ for trivia | 64 | * See http://www.in-ulm.de/~mascheck/various/shebang/ for trivia |
59 | * relating to '#!'. | 65 | * relating to '#!'. |
60 | */ | 66 | */ |
61 | if (buf[0] != '#' || buf[1] != '!') | 67 | if (interp->buf[0] != '#' || interp->buf[1] != '!') |
62 | return NULL; | 68 | return 0; |
63 | buf[n] = '\0'; | 69 | interp->buf[n] = '\0'; |
64 | if ((t=strchr(buf, '\n')) == NULL) | 70 | if ((t=strchr(interp->buf, '\n')) == NULL) |
65 | return NULL; | 71 | return 0; |
66 | t[1] = '\0'; | 72 | t[1] = '\0'; |
67 | 73 | ||
68 | if ((path=strtok(buf+2, " \t\r\n")) == NULL) | 74 | if ((path=strtok(interp->buf+2, " \t\r\n")) == NULL) |
69 | return NULL; | 75 | return 0; |
70 | 76 | ||
71 | t = (char *)bb_basename(path); | 77 | t = (char *)bb_basename(path); |
72 | if (*t == '\0') | 78 | if (*t == '\0') |
73 | return NULL; | 79 | return 0; |
74 | 80 | ||
75 | *name = t; | 81 | interp->path = path; |
76 | *opts = strtok(NULL, "\r\n"); | 82 | interp->name = t; |
83 | interp->opts = strtok(NULL, "\r\n"); | ||
77 | 84 | ||
78 | return path; | 85 | return 1; |
79 | } | 86 | } |
80 | 87 | ||
81 | /* | 88 | /* |
@@ -284,36 +291,35 @@ mingw_spawn_interpreter(int mode, const char *prog, char *const *argv, char *con | |||
284 | { | 291 | { |
285 | intptr_t ret; | 292 | intptr_t ret; |
286 | int nopts; | 293 | int nopts; |
287 | char *int_name, *opts; | 294 | interp_t interp; |
288 | char *int_path = parse_interpreter(prog, &int_name, &opts); | ||
289 | char **new_argv; | 295 | char **new_argv; |
290 | int argc = -1; | 296 | int argc = -1; |
291 | char *fullpath = NULL; | 297 | char *fullpath = NULL; |
292 | 298 | ||
293 | if (!int_path) | 299 | if (!parse_interpreter(prog, &interp)) |
294 | return spawnveq(mode, prog, argv, envp); | 300 | return spawnveq(mode, prog, argv, envp); |
295 | 301 | ||
296 | nopts = opts != NULL; | 302 | nopts = interp.opts != NULL; |
297 | while (argv[++argc]) | 303 | while (argv[++argc]) |
298 | ; | 304 | ; |
299 | 305 | ||
300 | new_argv = xmalloc(sizeof(*argv)*(argc+nopts+2)); | 306 | new_argv = xmalloc(sizeof(*argv)*(argc+nopts+2)); |
301 | new_argv[1] = opts; | 307 | new_argv[1] = interp.opts; |
302 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ | 308 | new_argv[nopts+1] = (char *)prog; /* pass absolute path */ |
303 | memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc); | 309 | memcpy(new_argv+nopts+2, argv+1, sizeof(*argv)*argc); |
304 | 310 | ||
305 | if ((fullpath=add_win32_extension(int_path)) != NULL || | 311 | if ((fullpath=add_win32_extension(interp.path)) != NULL || |
306 | file_is_executable(int_path)) { | 312 | file_is_executable(interp.path)) { |
307 | new_argv[0] = fullpath ? fullpath : int_path; | 313 | new_argv[0] = fullpath ? fullpath : interp.path; |
308 | ret = spawnveq(mode, new_argv[0], new_argv, envp); | 314 | ret = spawnveq(mode, new_argv[0], new_argv, envp); |
309 | } else | 315 | } else |
310 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE | 316 | #if ENABLE_FEATURE_PREFER_APPLETS || ENABLE_FEATURE_SH_STANDALONE |
311 | if (find_applet_by_name(int_name) >= 0) { | 317 | if (find_applet_by_name(interp.name) >= 0) { |
312 | new_argv[0] = int_name; | 318 | new_argv[0] = interp.name; |
313 | ret = mingw_spawn_applet(mode, new_argv, envp); | 319 | ret = mingw_spawn_applet(mode, new_argv, envp); |
314 | } else | 320 | } else |
315 | #endif | 321 | #endif |
316 | if ((fullpath=find_first_executable(int_name)) != NULL) { | 322 | if ((fullpath=find_first_executable(interp.name)) != NULL) { |
317 | new_argv[0] = fullpath; | 323 | new_argv[0] = fullpath; |
318 | ret = spawnveq(mode, fullpath, new_argv, envp); | 324 | ret = spawnveq(mode, fullpath, new_argv, envp); |
319 | } | 325 | } |