From b5c6c1e5506198d240dbc7f19caee8b95989aec3 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 22 Mar 2018 09:26:14 +0000 Subject: 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. --- win32/mingw.c | 17 ++++++----------- 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) HANDLE h; if (!buf) - buf = xmalloc(PATH_MAX); + buf = xzalloc(PATH_MAX); - buf[0] = '\0'; - if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h) ) + if (buf[0]) return buf; - if ( !GetUserProfileDirectory(h, buf, &len) ) { - CloseHandle(h); + if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h) ) return buf; - } + GetUserProfileDirectory(h, buf, &len); CloseHandle(h); - convert_slashes(buf); return buf; @@ -744,8 +741,7 @@ static char *get_user_name(void) DWORD len = NAME_LEN; if ( user_name == NULL ) { - user_name = xmalloc(NAME_LEN); - user_name[0] = '\0'; + user_name = xzalloc(NAME_LEN); } if ( user_name[0] != '\0' ) { @@ -901,8 +897,7 @@ const char *get_busybox_exec_path(void) static char *path = NULL; if (!path) { - path = xmalloc(PATH_MAX); - path[0] = '\0'; + path = xzalloc(PATH_MAX); } 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) if (stat(path, &st) == 0) { if (!S_ISREG(st.st_mode) || !(st.st_mode&S_IXUSR)) { errno = EACCES; - fprintf(stderr, "spawnveq: %s: %s\n", path, strerror(errno)); - return -1; + goto error; } } else { + error: fprintf(stderr, "spawnveq: %s: %s\n", path, strerror(errno)); return -1; } -- cgit v1.2.3-55-g6feb