aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-03-15 10:27:19 +0000
committerRon Yorston <rmy@pobox.com>2019-03-15 10:27:19 +0000
commit996f93243dda87de3140c497624312722f47ffa1 (patch)
tree8c894b5b7414cbd72f02bd309d54ffa62283915a /win32
parent79c85ec59075b5ead415a4713bd72445546dcf8e (diff)
downloadbusybox-w32-996f93243dda87de3140c497624312722f47ffa1.tar.gz
busybox-w32-996f93243dda87de3140c497624312722f47ffa1.tar.bz2
busybox-w32-996f93243dda87de3140c497624312722f47ffa1.zip
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().
Diffstat (limited to 'win32')
-rw-r--r--win32/mingw.c19
-rw-r--r--win32/process.c7
2 files changed, 16 insertions, 10 deletions
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)
778 char *ret = getcwd(pointer, len); 778 char *ret = getcwd(pointer, len);
779 if (!ret) 779 if (!ret)
780 return ret; 780 return ret;
781 convert_slashes(ret); 781 bs_to_slash(ret);
782 return ret; 782 return ret;
783} 783}
784 784
@@ -833,7 +833,7 @@ static char *gethomedir(void)
833 833
834 GetUserProfileDirectory(h, buf, &len); 834 GetUserProfileDirectory(h, buf, &len);
835 CloseHandle(h); 835 CloseHandle(h);
836 convert_slashes(buf); 836 bs_to_slash(buf);
837 837
838 return buf; 838 return buf;
839} 839}
@@ -1097,7 +1097,7 @@ char *realpath(const char *path, char *resolved_path)
1097 if (_fullpath(buffer, path, MAX_PATH) && 1097 if (_fullpath(buffer, path, MAX_PATH) &&
1098 (real_path=resolve_symlinks(buffer))) { 1098 (real_path=resolve_symlinks(buffer))) {
1099 strcpy(resolved_path, real_path); 1099 strcpy(resolved_path, real_path);
1100 convert_slashes(resolved_path); 1100 bs_to_slash(resolved_path);
1101 p = last_char_is(resolved_path, '/'); 1101 p = last_char_is(resolved_path, '/');
1102 if (p && p > resolved_path && p[-1] != ':') 1102 if (p && p > resolved_path && p[-1] != ':')
1103 *p = '\0'; 1103 *p = '\0';
@@ -1178,7 +1178,7 @@ const char *get_busybox_exec_path(void)
1178 1178
1179 if (!*path) { 1179 if (!*path) {
1180 GetModuleFileName(NULL, path, PATH_MAX); 1180 GetModuleFileName(NULL, path, PATH_MAX);
1181 convert_slashes(path); 1181 bs_to_slash(path);
1182 } 1182 }
1183 return path; 1183 return path;
1184} 1184}
@@ -1483,7 +1483,7 @@ char *alloc_win32_extension(const char *p)
1483 return NULL; 1483 return NULL;
1484} 1484}
1485 1485
1486void FAST_FUNC convert_slashes(char *p) 1486void FAST_FUNC bs_to_slash(char *p)
1487{ 1487{
1488 for (; *p; ++p) { 1488 for (; *p; ++p) {
1489 if ( *p == '\\' ) { 1489 if ( *p == '\\' ) {
@@ -1492,6 +1492,15 @@ void FAST_FUNC convert_slashes(char *p)
1492 } 1492 }
1493} 1493}
1494 1494
1495void FAST_FUNC slash_to_bs(char *p)
1496{
1497 for (; *p; ++p) {
1498 if ( *p == '/' ) {
1499 *p = '\\';
1500 }
1501 }
1502}
1503
1495size_t FAST_FUNC remove_cr(char *p, size_t len) 1504size_t FAST_FUNC remove_cr(char *p, size_t len)
1496{ 1505{
1497 ssize_t i, j; 1506 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
190spawnveq(int mode, const char *path, char *const *argv, char *const *env) 190spawnveq(int mode, const char *path, char *const *argv, char *const *env)
191{ 191{
192 char **new_argv; 192 char **new_argv;
193 char *s, *new_path = NULL; 193 char *new_path = NULL;
194 int i, argc; 194 int i, argc;
195 intptr_t ret; 195 intptr_t ret;
196 struct stat st; 196 struct stat st;
@@ -219,10 +219,7 @@ spawnveq(int mode, const char *path, char *const *argv, char *const *env)
219 * argument is a relative path containing forward slashes. Absolute 219 * argument is a relative path containing forward slashes. Absolute
220 * paths are fine but there's no harm in converting them too. */ 220 * paths are fine but there's no harm in converting them too. */
221 if (has_bat_suffix(path)) { 221 if (has_bat_suffix(path)) {
222 for (s=new_argv[0]; *s; ++s) { 222 slash_to_bs(new_argv[0]);
223 if (*s == '/')
224 *s = '\\';
225 }
226 223
227 /* Another special case: spawnve returns ENOEXEC when passed an 224 /* Another special case: spawnve returns ENOEXEC when passed an
228 * empty batch file. Pretend it worked. */ 225 * empty batch file. Pretend it worked. */