aboutsummaryrefslogtreecommitdiff
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
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().
-rw-r--r--debianutils/which.c6
-rw-r--r--include/mingw.h3
-rw-r--r--libbb/appletlib.c2
-rw-r--r--libbb/lineedit.c2
-rw-r--r--libbb/make_directory.c2
-rw-r--r--loginutils/suw32.c9
-rw-r--r--shell/ash.c4
-rw-r--r--win32/mingw.c19
-rw-r--r--win32/process.c7
9 files changed, 29 insertions, 25 deletions
diff --git a/debianutils/which.c b/debianutils/which.c
index b26f2f0f5..61f5770c5 100644
--- a/debianutils/which.c
+++ b/debianutils/which.c
@@ -69,7 +69,7 @@ int which_main(int argc UNUSED_PARAM, char **argv)
69#if ENABLE_PLATFORM_MINGW32 69#if ENABLE_PLATFORM_MINGW32
70 if ((p=auto_win32_extension(*argv)) != NULL) { 70 if ((p=auto_win32_extension(*argv)) != NULL) {
71 missing = 0; 71 missing = 0;
72 convert_slashes(p); 72 bs_to_slash(p);
73 puts(p); 73 puts(p);
74 } 74 }
75 else 75 else
@@ -78,7 +78,7 @@ int which_main(int argc UNUSED_PARAM, char **argv)
78 missing = 0; 78 missing = 0;
79#if ENABLE_PLATFORM_MINGW32 79#if ENABLE_PLATFORM_MINGW32
80 p = auto_string(xstrdup(*argv)); 80 p = auto_string(xstrdup(*argv));
81 convert_slashes(p); 81 bs_to_slash(p);
82 puts(p); 82 puts(p);
83#else 83#else
84 puts(*argv); 84 puts(*argv);
@@ -92,7 +92,7 @@ int which_main(int argc UNUSED_PARAM, char **argv)
92 while ((p = find_executable(*argv, &path)) != NULL) { 92 while ((p = find_executable(*argv, &path)) != NULL) {
93 missing = 0; 93 missing = 0;
94#if ENABLE_PLATFORM_MINGW32 94#if ENABLE_PLATFORM_MINGW32
95 convert_slashes(p); 95 bs_to_slash(p);
96#endif 96#endif
97 puts(p); 97 puts(p);
98 free(p); 98 free(p);
diff --git a/include/mingw.h b/include/mingw.h
index 7aa2d5cc9..36c2f6805 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -510,7 +510,8 @@ static inline char *auto_win32_extension(const char *p)
510 return s ? auto_string(s) : NULL; 510 return s ? auto_string(s) : NULL;
511} 511}
512 512
513void convert_slashes(char *p) FAST_FUNC; 513void bs_to_slash(char *p) FAST_FUNC;
514void slash_to_bs(char *p) FAST_FUNC;
514size_t remove_cr(char *p, size_t len) FAST_FUNC; 515size_t remove_cr(char *p, size_t len) FAST_FUNC;
515 516
516int err_win_to_posix(void); 517int err_win_to_posix(void);
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 49ae35874..35aabe758 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -1287,7 +1287,7 @@ int main(int argc UNUSED_PARAM, char **argv)
1287 char *s; 1287 char *s;
1288 1288
1289 str_tolower(argv[0]); 1289 str_tolower(argv[0]);
1290 convert_slashes(argv[0]); 1290 bs_to_slash(argv[0]);
1291 if (has_exe_suffix_or_dot(argv[0]) && (s=strrchr(argv[0], '.'))) { 1291 if (has_exe_suffix_or_dot(argv[0]) && (s=strrchr(argv[0], '.'))) {
1292 *s = '\0'; 1292 *s = '\0';
1293 } 1293 }
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index abe2857b2..3725dba0d 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -2611,7 +2611,7 @@ int FAST_FUNC read_line_input(line_input_t *st, const char *prompt, char *comman
2611#if ENABLE_PLATFORM_MINGW32 2611#if ENABLE_PLATFORM_MINGW32
2612 case CTRL('Z'): 2612 case CTRL('Z'):
2613 command_ps[command_len] = '\0'; 2613 command_ps[command_len] = '\0';
2614 convert_slashes(command_ps); 2614 bs_to_slash(command_ps);
2615 redraw(cmdedit_y, 0); 2615 redraw(cmdedit_y, 0);
2616 break; 2616 break;
2617#endif 2617#endif
diff --git a/libbb/make_directory.c b/libbb/make_directory.c
index ef0a8acd8..9af5552d5 100644
--- a/libbb/make_directory.c
+++ b/libbb/make_directory.c
@@ -51,7 +51,7 @@ int FAST_FUNC bb_make_directory(char *path, long mode, int flags)
51 org_mask = cur_mask = (mode_t)-1L; 51 org_mask = cur_mask = (mode_t)-1L;
52#if ENABLE_PLATFORM_MINGW32 52#if ENABLE_PLATFORM_MINGW32
53 /* normalise path separators, path is already assumed writable */ 53 /* normalise path separators, path is already assumed writable */
54 convert_slashes(path); 54 bs_to_slash(path);
55#endif 55#endif
56 s = path; 56 s = path;
57 while (1) { 57 while (1) {
diff --git a/loginutils/suw32.c b/loginutils/suw32.c
index e3c6d8744..de29f423a 100644
--- a/loginutils/suw32.c
+++ b/loginutils/suw32.c
@@ -28,18 +28,15 @@ int suw32_main(int argc UNUSED_PARAM, char **argv)
28{ 28{
29 char *opt_command = NULL; 29 char *opt_command = NULL;
30 SHELLEXECUTEINFO info; 30 SHELLEXECUTEINFO info;
31 char *bb_path, *cwd, *s; 31 char *bb_path, *cwd;
32 32
33 getopt32(argv, "c:", &opt_command); 33 getopt32(argv, "c:", &opt_command);
34 if (argv[optind]) 34 if (argv[optind])
35 bb_show_usage(); 35 bb_show_usage();
36 36
37 /* ShellExecuteEx() needs backslash as separator in UNC paths. */ 37 /* ShellExecuteEx() needs backslash as separator in UNC paths. */
38 bb_path = s = xstrdup(bb_busybox_exec_path); 38 bb_path = xstrdup(bb_busybox_exec_path);
39 for ( ; *s; ++s) { 39 slash_to_bs(bb_path);
40 if (*s == '/')
41 *s = '\\';
42 }
43 40
44 memset(&info, 0, sizeof(SHELLEXECUTEINFO)); 41 memset(&info, 0, sizeof(SHELLEXECUTEINFO));
45 info.cbSize = sizeof(SHELLEXECUTEINFO); 42 info.cbSize = sizeof(SHELLEXECUTEINFO);
diff --git a/shell/ash.c b/shell/ash.c
index 8daf263dc..4adad65aa 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -14696,7 +14696,7 @@ init(void)
14696 * cause problems */ 14696 * cause problems */
14697 if ( !winxp && strncmp(*envp, "SYSTEMROOT=", 11) != 0 && 14697 if ( !winxp && strncmp(*envp, "SYSTEMROOT=", 11) != 0 &&
14698 strncmp(*envp, "COMSPEC=", 8) != 0 ) { 14698 strncmp(*envp, "COMSPEC=", 8) != 0 ) {
14699 convert_slashes(end+1); 14699 bs_to_slash(end+1);
14700 } 14700 }
14701 14701
14702 /* check for invalid characters in name */ 14702 /* check for invalid characters in name */
@@ -14838,7 +14838,7 @@ procargs(char **argv)
14838 } else if (!sflag) { 14838 } else if (!sflag) {
14839 setinputfile(*xargv, 0); 14839 setinputfile(*xargv, 0);
14840#if ENABLE_PLATFORM_MINGW32 14840#if ENABLE_PLATFORM_MINGW32
14841 convert_slashes(*xargv); 14841 bs_to_slash(*xargv);
14842#endif 14842#endif
14843 setarg0: 14843 setarg0:
14844 arg0 = *xargv++; 14844 arg0 = *xargv++;
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. */