From 996f93243dda87de3140c497624312722f47ffa1 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 15 Mar 2019 10:27:19 +0000 Subject: win32: add function to convert slashes to backslashes There are now two places where slashes are converted to backslashes throughout a string so it makes sense to create a function to do this. To avoid confusion rename convert_slashes() to bs_to_slash() and call the new function slash_to_bs(). --- win32/mingw.c | 19 ++++++++++++++----- win32/process.c | 7 ++----- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index 3788e8a06..7552d19da 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -778,7 +778,7 @@ char *mingw_getcwd(char *pointer, int len) char *ret = getcwd(pointer, len); if (!ret) return ret; - convert_slashes(ret); + bs_to_slash(ret); return ret; } @@ -833,7 +833,7 @@ static char *gethomedir(void) GetUserProfileDirectory(h, buf, &len); CloseHandle(h); - convert_slashes(buf); + bs_to_slash(buf); return buf; } @@ -1097,7 +1097,7 @@ char *realpath(const char *path, char *resolved_path) if (_fullpath(buffer, path, MAX_PATH) && (real_path=resolve_symlinks(buffer))) { strcpy(resolved_path, real_path); - convert_slashes(resolved_path); + bs_to_slash(resolved_path); p = last_char_is(resolved_path, '/'); if (p && p > resolved_path && p[-1] != ':') *p = '\0'; @@ -1178,7 +1178,7 @@ const char *get_busybox_exec_path(void) if (!*path) { GetModuleFileName(NULL, path, PATH_MAX); - convert_slashes(path); + bs_to_slash(path); } return path; } @@ -1483,7 +1483,7 @@ char *alloc_win32_extension(const char *p) return NULL; } -void FAST_FUNC convert_slashes(char *p) +void FAST_FUNC bs_to_slash(char *p) { for (; *p; ++p) { if ( *p == '\\' ) { @@ -1492,6 +1492,15 @@ void FAST_FUNC convert_slashes(char *p) } } +void FAST_FUNC slash_to_bs(char *p) +{ + for (; *p; ++p) { + if ( *p == '/' ) { + *p = '\\'; + } + } +} + size_t FAST_FUNC remove_cr(char *p, size_t len) { ssize_t i, j; diff --git a/win32/process.c b/win32/process.c index d0fcc1c80..99db6f79f 100644 --- a/win32/process.c +++ b/win32/process.c @@ -190,7 +190,7 @@ static intptr_t spawnveq(int mode, const char *path, char *const *argv, char *const *env) { char **new_argv; - char *s, *new_path = NULL; + char *new_path = NULL; int i, argc; intptr_t ret; struct stat st; @@ -219,10 +219,7 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env) * argument is a relative path containing forward slashes. Absolute * paths are fine but there's no harm in converting them too. */ if (has_bat_suffix(path)) { - for (s=new_argv[0]; *s; ++s) { - if (*s == '/') - *s = '\\'; - } + slash_to_bs(new_argv[0]); /* Another special case: spawnve returns ENOEXEC when passed an * empty batch file. Pretend it worked. */ -- cgit v1.2.3-55-g6feb