aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libbb.h6
-rw-r--r--include/mingw.h1
-rw-r--r--libbb/executable.c15
-rw-r--r--libbb/lineedit.c12
-rw-r--r--miscutils/man.c17
-rw-r--r--shell/ash.c86
-rw-r--r--win32/process.c20
7 files changed, 75 insertions, 82 deletions
diff --git a/include/libbb.h b/include/libbb.h
index a17da9c1f..8b18782c8 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -2130,7 +2130,13 @@ extern const char bb_busybox_exec_path[] ALIGN1;
2130#ifndef BB_ADDITIONAL_PATH 2130#ifndef BB_ADDITIONAL_PATH
2131#define BB_ADDITIONAL_PATH "" 2131#define BB_ADDITIONAL_PATH ""
2132#endif 2132#endif
2133#if !ENABLE_PLATFORM_MINGW32
2133#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH 2134#define BB_PATH_ROOT_PATH "PATH=/sbin:/usr/sbin:/bin:/usr/bin" BB_ADDITIONAL_PATH
2135#define PATH_SEP ':'
2136#else
2137#define BB_PATH_ROOT_PATH "PATH=/sbin;/usr/sbin;/bin;/usr/bin" BB_ADDITIONAL_PATH
2138#define PATH_SEP ';'
2139#endif
2134extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */ 2140extern const char bb_PATH_root_path[] ALIGN1; /* BB_PATH_ROOT_PATH */
2135#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH")) 2141#define bb_default_root_path (bb_PATH_root_path + sizeof("PATH"))
2136/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin, 2142/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
diff --git a/include/mingw.h b/include/mingw.h
index 8a695d2d2..cef53a7c9 100644
--- a/include/mingw.h
+++ b/include/mingw.h
@@ -443,7 +443,6 @@ int mingw_execve(const char *cmd, char *const *argv, char *const *envp);
443#define execve mingw_execve 443#define execve mingw_execve
444#define execv mingw_execv 444#define execv mingw_execv
445 445
446const char * next_path_sep(const char *path);
447#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':') 446#define has_dos_drive_prefix(path) (isalpha(*(path)) && (path)[1] == ':')
448#define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path)) 447#define is_absolute_path(path) ((path)[0] == '/' || (path)[0] == '\\' || has_dos_drive_prefix(path))
449 448
diff --git a/libbb/executable.c b/libbb/executable.c
index 835341ed9..87a40eeda 100644
--- a/libbb/executable.c
+++ b/libbb/executable.c
@@ -40,28 +40,21 @@ char* FAST_FUNC find_executable(const char *filename, char **PATHp)
40 */ 40 */
41 char *p, *n; 41 char *p, *n;
42#if ENABLE_PLATFORM_MINGW32 42#if ENABLE_PLATFORM_MINGW32
43 char sep, *w; 43 char *w;
44#endif 44#endif
45 45
46 p = *PATHp; 46 p = *PATHp;
47 while (p) { 47 while (p) {
48 int ex; 48 int ex;
49 49
50#if !ENABLE_PLATFORM_MINGW32 50 n = strchr(p, PATH_SEP);
51 n = strchr(p, ':');
52 if (n) *n = '\0'; 51 if (n) *n = '\0';
53#else
54 n = (char*)next_path_sep(p);
55 if (n) { sep = *n; *n = '\0'; }
56#endif
57 p = concat_path_file( 52 p = concat_path_file(
58 p[0] ? p : ".", /* handle "::" case */ 53 p[0] ? p : ".", /* handle "::" case */
59 filename 54 filename
60 ); 55 );
61#if !ENABLE_PLATFORM_MINGW32 56 if (n) *n++ = PATH_SEP;
62 if (n) *n++ = ':'; 57#if ENABLE_PLATFORM_MINGW32
63#else
64 if (n) *n++ = sep;
65 if ((w=alloc_win32_extension(p))) { 58 if ((w=alloc_win32_extension(p))) {
66 free(p); 59 free(p);
67 p = w; 60 p = w;
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 89178bbc3..6513219ce 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -798,11 +798,7 @@ static int path_parse(char ***p)
798 tmp = (char*)pth; 798 tmp = (char*)pth;
799 npth = 1; /* path component count */ 799 npth = 1; /* path component count */
800 while (1) { 800 while (1) {
801#if ENABLE_PLATFORM_MINGW32 801 tmp = strchr(tmp, PATH_SEP);
802 tmp = (char *)next_path_sep(tmp);
803#else
804 tmp = strchr(tmp, ':');
805#endif
806 if (!tmp) 802 if (!tmp)
807 break; 803 break;
808 tmp++; 804 tmp++;
@@ -815,11 +811,7 @@ static int path_parse(char ***p)
815 res[0] = tmp = xstrdup(pth); 811 res[0] = tmp = xstrdup(pth);
816 npth = 1; 812 npth = 1;
817 while (1) { 813 while (1) {
818#if ENABLE_PLATFORM_MINGW32 814 tmp = strchr(tmp, PATH_SEP);
819 tmp = (char *)next_path_sep(tmp);
820#else
821 tmp = strchr(tmp, ':');
822#endif
823 if (!tmp) 815 if (!tmp)
824 break; 816 break;
825 *tmp++ = '\0'; /* ':' -> '\0' */ 817 *tmp++ = '\0'; /* ':' -> '\0' */
diff --git a/miscutils/man.c b/miscutils/man.c
index 567323a88..4ff58a9a0 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -199,19 +199,10 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
199 if (path) while (*path) { 199 if (path) while (*path) {
200 char *next_path; 200 char *next_path;
201 char **path_element; 201 char **path_element;
202#if ENABLE_PLATFORM_MINGW32 202 next_path = strchr(path, PATH_SEP);
203 char save;
204
205 next_path = (char *)next_path_sep(path);
206#else
207 next_path = strchr(path, ':');
208#endif
209 if (next_path) { 203 if (next_path) {
210 if (next_path == path) /* "::"? */ 204 if (next_path == path) /* "::"? */
211 goto next; 205 goto next;
212#if ENABLE_PLATFORM_MINGW32
213 save = *next_path;
214#endif
215 *next_path = '\0'; 206 *next_path = '\0';
216 } 207 }
217 /* Do we already have path? */ 208 /* Do we already have path? */
@@ -230,11 +221,7 @@ static char **add_MANPATH(char **man_path_list, int *count_mp, char *path)
230 if (!next_path) 221 if (!next_path)
231 break; 222 break;
232 /* "path" may be a result of getenv(), be nice and don't mangle it */ 223 /* "path" may be a result of getenv(), be nice and don't mangle it */
233#if ENABLE_PLATFORM_MINGW32 224 *next_path = PATH_SEP;
234 *next_path = save;
235#else
236 *next_path = ':';
237#endif
238 next: 225 next:
239 path = next_path + 1; 226 path = next_path + 1;
240 } 227 }
diff --git a/shell/ash.c b/shell/ash.c
index 3bbfbd694..a659fd703 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2422,6 +2422,42 @@ bltinlookup(const char *name)
2422 return lookupvar(name); 2422 return lookupvar(name);
2423} 2423}
2424 2424
2425#if ENABLE_PLATFORM_MINGW32
2426static char *
2427fix_pathvar(const char *path)
2428{
2429 char *newpath = xstrdup(path);
2430 char *p;
2431 int modified = FALSE;
2432
2433 p = newpath + 5;
2434 while (*p) {
2435 if (*p != ':' && *p != ';') {
2436 /* skip drive */
2437 if (isalpha(*p) && p[1] == ':')
2438 p += 2;
2439 /* skip through path component */
2440 for (; *p != '\0' && *p != ':' && *p != ';'; ++p)
2441 continue;
2442 }
2443 /* *p is ':', ';' or '\0' here */
2444 if (*p == ':') {
2445 *p++ = ';';
2446 modified = TRUE;
2447 }
2448 else if (*p == ';') {
2449 ++p;
2450 }
2451 }
2452
2453 if (!modified) {
2454 free(newpath);
2455 newpath = NULL;
2456 }
2457 return newpath;
2458}
2459#endif
2460
2425/* 2461/*
2426 * Same as setvar except that the variable and value are passed in 2462 * Same as setvar except that the variable and value are passed in
2427 * the first argument as name=value. Since the first argument will 2463 * the first argument as name=value. Since the first argument will
@@ -2434,6 +2470,19 @@ setvareq(char *s, int flags)
2434{ 2470{
2435 struct var *vp, **vpp; 2471 struct var *vp, **vpp;
2436 2472
2473#if ENABLE_PLATFORM_MINGW32
2474 if (strncmp(s, "PATH=", 5) == 0) {
2475 char *newpath = fix_pathvar(s);
2476 if (newpath) {
2477 if ((flags & (VTEXTFIXED|VSTACK|VNOSAVE)) == VNOSAVE)
2478 free(s);
2479 flags |= VNOSAVE;
2480 flags &= ~(VTEXTFIXED|VSTACK);
2481 s = newpath;
2482 }
2483 }
2484#endif
2485
2437 vpp = hashvar(s); 2486 vpp = hashvar(s);
2438 flags |= (VEXPORT & (((unsigned) (1 - aflag)) - 1)); 2487 flags |= (VEXPORT & (((unsigned) (1 - aflag)) - 1));
2439 vpp = findvar(vpp, s); 2488 vpp = findvar(vpp, s);
@@ -2646,18 +2695,8 @@ path_advance(const char **path, const char *name)
2646 if (*path == NULL) 2695 if (*path == NULL)
2647 return NULL; 2696 return NULL;
2648 start = *path; 2697 start = *path;
2649#if ENABLE_PLATFORM_MINGW32 2698 for (p = start; *p && *p != PATH_SEP && *p != '%'; p++)
2650 p = next_path_sep(start);
2651 q = strchr(start, '%');
2652 if ((p && q && q < p) || (!p && q))
2653 p = q;
2654 if (!p)
2655 for (p = start; *p; p++)
2656 continue;
2657#else
2658 for (p = start; *p && *p != ':' && *p != '%'; p++)
2659 continue; 2699 continue;
2660#endif
2661 len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */ 2700 len = p - start + strlen(name) + 2; /* "2" is for '/' and '\0' */
2662 2701
2663 /* reserve space for suffix on WIN32 */ 2702 /* reserve space for suffix on WIN32 */
@@ -2672,19 +2711,10 @@ path_advance(const char **path, const char *name)
2672 pathopt = NULL; 2711 pathopt = NULL;
2673 if (*p == '%') { 2712 if (*p == '%') {
2674 pathopt = ++p; 2713 pathopt = ++p;
2675#if ENABLE_PLATFORM_MINGW32 2714 while (*p && *p != PATH_SEP)
2676 p = next_path_sep(start);
2677
2678 /* *p != ':' and '*' would suffice */
2679 if (!p)
2680 p = pathopt - 1;
2681#else
2682 while (*p && *p != ':')
2683 p++; 2715 p++;
2684#endif
2685 } 2716 }
2686 if (*p == ':' || 2717 if (*p == PATH_SEP)
2687 (ENABLE_PLATFORM_MINGW32 && *p == ';'))
2688 *path = p + 1; 2718 *path = p + 1;
2689 else 2719 else
2690 *path = NULL; 2720 *path = NULL;
@@ -8733,8 +8763,8 @@ changepath(const char *new)
8733 for (;;) { 8763 for (;;) {
8734 if (*old != *new) { 8764 if (*old != *new) {
8735 firstchange = idx; 8765 firstchange = idx;
8736 if ((*old == '\0' && *new == ':') 8766 if ((*old == '\0' && *new == PATH_SEP)
8737 || (*old == ':' && *new == '\0') 8767 || (*old == PATH_SEP && *new == '\0')
8738 ) { 8768 ) {
8739 firstchange++; 8769 firstchange++;
8740 } 8770 }
@@ -8744,7 +8774,7 @@ changepath(const char *new)
8744 break; 8774 break;
8745 if (*new == '%' && idx_bltin < 0 && prefix(new + 1, "builtin")) 8775 if (*new == '%' && idx_bltin < 0 && prefix(new + 1, "builtin"))
8746 idx_bltin = idx; 8776 idx_bltin = idx;
8747 if (*new == ':') 8777 if (*new == PATH_SEP)
8748 idx++; 8778 idx++;
8749 new++; 8779 new++;
8750 old++; 8780 old++;
@@ -10585,7 +10615,13 @@ evalcommand(union node *cmd, int flags)
10585 */ 10615 */
10586 p = (*spp)->text; 10616 p = (*spp)->text;
10587 if (varcmp(p, path) == 0) 10617 if (varcmp(p, path) == 0)
10618#if !ENABLE_PLATFORM_MINGW32
10588 path = p; 10619 path = p;
10620#else
10621 /* fix_pathvar may have modified the value of the local
10622 * variable so we look it up again */
10623 path = vpath.var_text;
10624#endif
10589 } 10625 }
10590 10626
10591 /* Print the command if xflag is set. */ 10627 /* Print the command if xflag is set. */
diff --git a/win32/process.c b/win32/process.c
index 60fea01ad..37496db7b 100644
--- a/win32/process.c
+++ b/win32/process.c
@@ -24,26 +24,6 @@ int waitpid(pid_t pid, int *status, int options)
24 return -1; 24 return -1;
25} 25}
26 26
27const char *
28next_path_sep(const char *path)
29{
30 static const char *from = NULL, *to;
31 static int has_semicolon;
32 int len = strlen(path);
33
34 if (!from || !(path >= from && path+len <= to)) {
35 from = path;
36 to = from+len;
37 has_semicolon = strchr(path, ';') != NULL;
38 }
39
40 /* Semicolons take precedence, it's Windows PATH */
41 if (has_semicolon)
42 return strchr(path, ';');
43 /* PATH=C:, not really a separator */
44 return strchr(has_dos_drive_prefix(path) ? path+2 : path, ':');
45}
46
47typedef struct { 27typedef struct {
48 char *path; 28 char *path;
49 char *name; 29 char *name;