diff options
author | Ron Yorston <rmy@pobox.com> | 2020-08-23 10:16:12 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-08-23 10:16:12 +0100 |
commit | 64ecd10486934c12336dac84c67a1939dce0e096 (patch) | |
tree | 73e8bc6b07176b84295fd07f19828292a240f693 /win32/mingw.c | |
parent | d6b557547551dd80a389f361a995a97ef5930a63 (diff) | |
download | busybox-w32-64ecd10486934c12336dac84c67a1939dce0e096.tar.gz busybox-w32-64ecd10486934c12336dac84c67a1939dce0e096.tar.bz2 busybox-w32-64ecd10486934c12336dac84c67a1939dce0e096.zip |
win32: code shrink Unix-style path handling
Replace auto_add_system_drive() with alloc_system_drive() which
leaves space for a possible filename extension. This makes it
possible to drop alloc_win32_extension() and auto_win32_extension().
Saves 144 bytes.
Diffstat (limited to 'win32/mingw.c')
-rw-r--r-- | win32/mingw.c | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 4ffc49e9a..051dc3c0d 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -1496,25 +1496,6 @@ int add_win32_extension(char *p) | |||
1496 | return FALSE; | 1496 | return FALSE; |
1497 | } | 1497 | } |
1498 | 1498 | ||
1499 | /* Check if path can be made into an executable by adding a suffix. | ||
1500 | * Return an allocated string containing the path if it can; | ||
1501 | * return NULL if not. | ||
1502 | * | ||
1503 | * If path already has a suffix don't even bother trying. | ||
1504 | */ | ||
1505 | char *alloc_win32_extension(const char *p) | ||
1506 | { | ||
1507 | if (!has_exe_suffix_or_dot(p)) { | ||
1508 | int len = strlen(p); | ||
1509 | char *path = strcpy(xmalloc(len+5), p); | ||
1510 | |||
1511 | if (add_win32_extension(path)) | ||
1512 | return path; | ||
1513 | free(path); | ||
1514 | } | ||
1515 | return NULL; | ||
1516 | } | ||
1517 | |||
1518 | char * FAST_FUNC bs_to_slash(char *str) | 1499 | char * FAST_FUNC bs_to_slash(char *str) |
1519 | { | 1500 | { |
1520 | char *p; | 1501 | char *p; |
@@ -1706,11 +1687,14 @@ const char *need_system_drive(const char *path) | |||
1706 | return NULL; | 1687 | return NULL; |
1707 | } | 1688 | } |
1708 | 1689 | ||
1709 | /* Add a system drive prefix to 'path' if necessary, else return 'path' */ | 1690 | /* Allocate a string long enough to allow a system drive prefix and |
1710 | char *auto_add_system_drive(const char *path) | 1691 | * file extension to be added to path. Add the prefix if necessary. */ |
1692 | char *alloc_system_drive(const char *path) | ||
1711 | { | 1693 | { |
1712 | const char *sd = need_system_drive(path); | 1694 | const char *sd = need_system_drive(path); |
1713 | return sd ? auto_string(concat_path_file(sd, path)) : (char *)path; | 1695 | char *s = xmalloc(strlen(path) + 5 + (sd ? strlen(sd) : 0)); |
1696 | sprintf(s, "%s%s", sd ?: "", path); | ||
1697 | return s; | ||
1714 | } | 1698 | } |
1715 | 1699 | ||
1716 | int chdir_system_drive(void) | 1700 | int chdir_system_drive(void) |
@@ -1822,7 +1806,7 @@ void *get_proc_addr(const char *dll, const char *function, | |||
1822 | int unix_path(const char *path) | 1806 | int unix_path(const char *path) |
1823 | { | 1807 | { |
1824 | int i; | 1808 | int i; |
1825 | char *p = strdup(path); | 1809 | char *p = xstrdup(path); |
1826 | 1810 | ||
1827 | #define UNIX_PATHS "/bin\0/usr/bin\0/sbin\0/usr/sbin\0" | 1811 | #define UNIX_PATHS "/bin\0/usr/bin\0/sbin\0/usr/sbin\0" |
1828 | i = index_in_strings(UNIX_PATHS, dirname(p)); | 1812 | i = index_in_strings(UNIX_PATHS, dirname(p)); |