aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-02-13 11:44:28 +0000
committerRon Yorston <rmy@pobox.com>2020-02-13 11:44:28 +0000
commitf21cc9e93a6132d0471441569adfa86197f79ead (patch)
tree6c9118aa975d254bb8063ec8eb3f8c7717a330d1
parentbeba51059500737e6c004d7a8b0d196278115860 (diff)
downloadbusybox-w32-f21cc9e93a6132d0471441569adfa86197f79ead.tar.gz
busybox-w32-f21cc9e93a6132d0471441569adfa86197f79ead.tar.bz2
busybox-w32-f21cc9e93a6132d0471441569adfa86197f79ead.zip
win32: code shrink
Have bs_to_slash() return a pointer to its argument. This allows some calls to be chained, saving 32 bytes.
-rw-r--r--debianutils/which.c12
-rw-r--r--include/mingw.h2
-rw-r--r--win32/mingw.c20
3 files changed, 15 insertions, 19 deletions
diff --git a/debianutils/which.c b/debianutils/which.c
index 61f5770c5..715bd8d5e 100644
--- a/debianutils/which.c
+++ b/debianutils/which.c
@@ -69,17 +69,14 @@ 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 bs_to_slash(p); 72 puts(bs_to_slash(p));
73 puts(p);
74 } 73 }
75 else 74 else
76#endif 75#endif
77 if (file_is_executable(*argv)) { 76 if (file_is_executable(*argv)) {
78 missing = 0; 77 missing = 0;
79#if ENABLE_PLATFORM_MINGW32 78#if ENABLE_PLATFORM_MINGW32
80 p = auto_string(xstrdup(*argv)); 79 puts(bs_to_slash(auto_string(xstrdup(*argv))));
81 bs_to_slash(p);
82 puts(p);
83#else 80#else
84 puts(*argv); 81 puts(*argv);
85#endif 82#endif
@@ -92,9 +89,10 @@ int which_main(int argc UNUSED_PARAM, char **argv)
92 while ((p = find_executable(*argv, &path)) != NULL) { 89 while ((p = find_executable(*argv, &path)) != NULL) {
93 missing = 0; 90 missing = 0;
94#if ENABLE_PLATFORM_MINGW32 91#if ENABLE_PLATFORM_MINGW32
95 bs_to_slash(p); 92 puts(bs_to_slash(p));
96#endif 93#else
97 puts(p); 94 puts(p);
95#endif
98 free(p); 96 free(p);
99 if (!option_mask32) /* -a not set */ 97 if (!option_mask32) /* -a not set */
100 break; 98 break;
diff --git a/include/mingw.h b/include/mingw.h
index 2a543160a..4aca7e884 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -513,7 +513,7 @@ static inline char *auto_win32_extension(const char *p)
513 return s ? auto_string(s) : NULL; 513 return s ? auto_string(s) : NULL;
514} 514}
515 515
516void bs_to_slash(char *p) FAST_FUNC; 516char *bs_to_slash(char *p) FAST_FUNC;
517void slash_to_bs(char *p) FAST_FUNC; 517void slash_to_bs(char *p) FAST_FUNC;
518size_t remove_cr(char *p, size_t len) FAST_FUNC; 518size_t remove_cr(char *p, size_t len) FAST_FUNC;
519 519
diff --git a/win32/mingw.c b/win32/mingw.c
index 8f4d155b8..bada160da 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -791,8 +791,7 @@ char *mingw_getcwd(char *pointer, int len)
791 char *ret = getcwd(pointer, len); 791 char *ret = getcwd(pointer, len);
792 if (!ret) 792 if (!ret)
793 return ret; 793 return ret;
794 bs_to_slash(ret); 794 return bs_to_slash(ret);
795 return ret;
796} 795}
797 796
798#undef rename 797#undef rename
@@ -846,9 +845,7 @@ static char *gethomedir(void)
846 845
847 GetUserProfileDirectory(h, buf, &len); 846 GetUserProfileDirectory(h, buf, &len);
848 CloseHandle(h); 847 CloseHandle(h);
849 bs_to_slash(buf); 848 return bs_to_slash(buf);
850
851 return buf;
852} 849}
853 850
854#define NAME_LEN 100 851#define NAME_LEN 100
@@ -1109,8 +1106,7 @@ char *realpath(const char *path, char *resolved_path)
1109 1106
1110 if (_fullpath(buffer, path, MAX_PATH) && 1107 if (_fullpath(buffer, path, MAX_PATH) &&
1111 (real_path=resolve_symlinks(buffer))) { 1108 (real_path=resolve_symlinks(buffer))) {
1112 strcpy(resolved_path, real_path); 1109 bs_to_slash(strcpy(resolved_path, real_path));
1113 bs_to_slash(resolved_path);
1114 p = last_char_is(resolved_path, '/'); 1110 p = last_char_is(resolved_path, '/');
1115 if (p && p > resolved_path && p[-1] != ':') 1111 if (p && p > resolved_path && p[-1] != ':')
1116 *p = '\0'; 1112 *p = '\0';
@@ -1496,13 +1492,16 @@ char *alloc_win32_extension(const char *p)
1496 return NULL; 1492 return NULL;
1497} 1493}
1498 1494
1499void FAST_FUNC bs_to_slash(char *p) 1495char * FAST_FUNC bs_to_slash(char *str)
1500{ 1496{
1501 for (; *p; ++p) { 1497 char *p;
1498
1499 for (p=str; *p; ++p) {
1502 if ( *p == '\\' ) { 1500 if ( *p == '\\' ) {
1503 *p = '/'; 1501 *p = '/';
1504 } 1502 }
1505 } 1503 }
1504 return str;
1506} 1505}
1507 1506
1508void FAST_FUNC slash_to_bs(char *p) 1507void FAST_FUNC slash_to_bs(char *p)
@@ -1723,8 +1722,7 @@ char *get_drive_cwd(const char *path, char *buffer, int size)
1723 ret = GetFullPathName(drive, size, buffer, NULL); 1722 ret = GetFullPathName(drive, size, buffer, NULL);
1724 if (ret == 0 || ret > size) 1723 if (ret == 0 || ret > size)
1725 return NULL; 1724 return NULL;
1726 bs_to_slash(buffer); 1725 return bs_to_slash(buffer);
1727 return buffer;
1728} 1726}
1729 1727
1730void fix_path_case(char *path) 1728void fix_path_case(char *path)