diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-22 09:26:14 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-22 09:26:14 +0000 |
commit | b5c6c1e5506198d240dbc7f19caee8b95989aec3 (patch) | |
tree | 527f7060a2b852a2aed527b51a4037da31ca6c5d | |
parent | 4e14b2a8e2dbe1987586468cb0c79313d0af08cd (diff) | |
download | busybox-w32-b5c6c1e5506198d240dbc7f19caee8b95989aec3.tar.gz busybox-w32-b5c6c1e5506198d240dbc7f19caee8b95989aec3.tar.bz2 busybox-w32-b5c6c1e5506198d240dbc7f19caee8b95989aec3.zip |
win32: small changes to reduce size of binary
Reduce the size of the binary by about 32 bytes:
- use xzalloc to allocate static buffers so we don't have to
initialise them;
- avoid duplicated code in spawnveq.
-rw-r--r-- | win32/mingw.c | 17 | ||||
-rw-r--r-- | win32/process.c | 4 |
2 files changed, 8 insertions, 13 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 9978baa7a..d73a4d96e 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -718,19 +718,16 @@ static char *gethomedir(void) | |||
718 | HANDLE h; | 718 | HANDLE h; |
719 | 719 | ||
720 | if (!buf) | 720 | if (!buf) |
721 | buf = xmalloc(PATH_MAX); | 721 | buf = xzalloc(PATH_MAX); |
722 | 722 | ||
723 | buf[0] = '\0'; | 723 | if (buf[0]) |
724 | if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h) ) | ||
725 | return buf; | 724 | return buf; |
726 | 725 | ||
727 | if ( !GetUserProfileDirectory(h, buf, &len) ) { | 726 | if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h) ) |
728 | CloseHandle(h); | ||
729 | return buf; | 727 | return buf; |
730 | } | ||
731 | 728 | ||
729 | GetUserProfileDirectory(h, buf, &len); | ||
732 | CloseHandle(h); | 730 | CloseHandle(h); |
733 | |||
734 | convert_slashes(buf); | 731 | convert_slashes(buf); |
735 | 732 | ||
736 | return buf; | 733 | return buf; |
@@ -744,8 +741,7 @@ static char *get_user_name(void) | |||
744 | DWORD len = NAME_LEN; | 741 | DWORD len = NAME_LEN; |
745 | 742 | ||
746 | if ( user_name == NULL ) { | 743 | if ( user_name == NULL ) { |
747 | user_name = xmalloc(NAME_LEN); | 744 | user_name = xzalloc(NAME_LEN); |
748 | user_name[0] = '\0'; | ||
749 | } | 745 | } |
750 | 746 | ||
751 | if ( user_name[0] != '\0' ) { | 747 | if ( user_name[0] != '\0' ) { |
@@ -901,8 +897,7 @@ const char *get_busybox_exec_path(void) | |||
901 | static char *path = NULL; | 897 | static char *path = NULL; |
902 | 898 | ||
903 | if (!path) { | 899 | if (!path) { |
904 | path = xmalloc(PATH_MAX); | 900 | path = xzalloc(PATH_MAX); |
905 | path[0] = '\0'; | ||
906 | } | 901 | } |
907 | 902 | ||
908 | if (!*path) { | 903 | if (!*path) { |
diff --git a/win32/process.c b/win32/process.c index 0d6d70970..8842e0dee 100644 --- a/win32/process.c +++ b/win32/process.c | |||
@@ -211,11 +211,11 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env) | |||
211 | if (stat(path, &st) == 0) { | 211 | if (stat(path, &st) == 0) { |
212 | if (!S_ISREG(st.st_mode) || !(st.st_mode&S_IXUSR)) { | 212 | if (!S_ISREG(st.st_mode) || !(st.st_mode&S_IXUSR)) { |
213 | errno = EACCES; | 213 | errno = EACCES; |
214 | fprintf(stderr, "spawnveq: %s: %s\n", path, strerror(errno)); | 214 | goto error; |
215 | return -1; | ||
216 | } | 215 | } |
217 | } | 216 | } |
218 | else { | 217 | else { |
218 | error: | ||
219 | fprintf(stderr, "spawnveq: %s: %s\n", path, strerror(errno)); | 219 | fprintf(stderr, "spawnveq: %s: %s\n", path, strerror(errno)); |
220 | return -1; | 220 | return -1; |
221 | } | 221 | } |