From 411d8b4cf9887c108853a25388837c1aaf31edce Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sun, 18 Mar 2018 19:57:54 +0000 Subject: win32: add a function to convert backslashes to slashes --- include/mingw.h | 3 +-- libbb/make_directory.c | 6 +----- shell/ash.c | 8 ++------ win32/mingw.c | 25 ++++++++++++++----------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index 386540b37..a54a6ac85 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -442,8 +442,6 @@ const char * next_path_sep(const char *path); * helpers */ -char **env_setenv(char **env, const char *name); - const char *get_busybox_exec_path(void); void init_winsock(void); @@ -451,6 +449,7 @@ int has_bat_suffix(const char *p); int has_exe_suffix(const char *p); int has_exe_suffix_or_dot(const char *name); char *add_win32_extension(const char *p); +void FAST_FUNC convert_slashes(char *p); int err_win_to_posix(DWORD winerr); diff --git a/libbb/make_directory.c b/libbb/make_directory.c index 1f3aecf40..ef0a8acd8 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -51,11 +51,7 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags) org_mask = cur_mask = (mode_t)-1L; #if ENABLE_PLATFORM_MINGW32 /* normalise path separators, path is already assumed writable */ - for (s=path; *s; ++s) { - if (*s == '\\') { - *s = '/'; - } - } + convert_slashes(path); #endif s = path; while (1) { diff --git a/shell/ash.c b/shell/ash.c index 778d8bd9d..c7c514417 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -14430,7 +14430,7 @@ init(void) * variable called something other than PATH. This suggests we * haven't been invoked from an earlier instance of BusyBox. */ - char *start, *end, *s; + char *start, *end; struct passwd *pw; for (envp = environ; envp && *envp; envp++) { @@ -14449,11 +14449,7 @@ init(void) /* convert backslashes to forward slashes in value */ if (!xp) { - for ( s=end+1; *s; ++s ) { - if ( *s == '\\' ) { - *s = '/'; - } - } + convert_slashes(end+1); } /* check for invalid characters in name */ diff --git a/win32/mingw.c b/win32/mingw.c index ee549c311..112b2a54e 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -665,13 +665,10 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) #undef getcwd char *mingw_getcwd(char *pointer, int len) { - int i; char *ret = getcwd(pointer, len); if (!ret) return ret; - for (i = 0; ret[i]; i++) - if (ret[i] == '\\') - ret[i] = '/'; + convert_slashes(ret); return ret; } @@ -714,7 +711,6 @@ static char *gethomedir(void) static char *buf = NULL; DWORD len = PATH_MAX; HANDLE h; - char *s; if (!buf) buf = xmalloc(PATH_MAX); @@ -730,11 +726,7 @@ static char *gethomedir(void) CloseHandle(h); - for ( s=buf; *s; ++s ) { - if ( *s == '\\' ) { - *s = '/'; - } - } + convert_slashes(buf); return buf; } @@ -908,8 +900,10 @@ const char *get_busybox_exec_path(void) path[0] = '\0'; } - if (!*path) + if (!*path) { GetModuleFileName(NULL, path, PATH_MAX); + convert_slashes(path); + } return path; } @@ -1174,6 +1168,15 @@ char *add_win32_extension(const char *p) return NULL; } +void FAST_FUNC convert_slashes(char *p) +{ + for (; *p; ++p) { + if ( *p == '\\' ) { + *p = '/'; + } + } +} + #undef opendir DIR *mingw_opendir(const char *path) { -- cgit v1.2.3-55-g6feb