From a694cb601a92a1e4eded89f4c13793c9d12e33b6 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 7 Jul 2024 12:51:51 +0100 Subject: win32: code shrink system drive handling A previous commit (e3bfe3695) revised the use of getsysdir() to obtain the system directory, and hence the system drive. See the commit message for the history to that point. Further improvements are possible: - Remove getsysdir() and push the calls to GetSystemDirectory() down into get_system_drive() and get_proc_addr(). - Check the return value of GetSystemDirectory(). It's unlikely to fail, but better safe than sorry. - Instead of making all callers of get_system_drive() check for a NULL return value always return a non-NULL pointer. If the drive can't be found an empty string is returned instead (which is what the callers were using anyway). - The function need_system_drive() was only used in one place (in httpd). Move the code there and remove the function. - Use concat_path_file() where possible. Saves 76-144 bytes. --- include/mingw.h | 1 - libbb/appletlib.c | 6 +++--- networking/httpd.c | 7 ++++--- shell/ash.c | 2 +- win32/mingw.c | 41 ++++++++++++++--------------------------- 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index 93fad0605..b0342337d 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -622,7 +622,6 @@ int enumerate_links(const char *file, char *name); int unc_root_len(const char *dir); int root_len(const char *path); const char *get_system_drive(void); -const char *need_system_drive(const char *path); int chdir_system_drive(void); char *xabsolute_path(char *path); char *get_drive_cwd(const char *path, char *buffer, int size); diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 54be59f2d..97dfb3df8 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c @@ -781,7 +781,7 @@ static void install_links(const char *busybox, int use_symbolic_links, unsigned i; int rc; # if ENABLE_PLATFORM_MINGW32 - const char *sd = NULL; + const char *sd = ""; if (custom_install_dir != NULL) { bb_make_directory(custom_install_dir, 0755, FILEUTILS_RECUR); @@ -789,7 +789,7 @@ static void install_links(const char *busybox, int use_symbolic_links, else { sd = get_system_drive(); for (i=1; i