aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-08-13 13:56:17 +0100
committerRon Yorston <rmy@pobox.com>2020-08-13 14:58:01 +0100
commit6059723900f2af1fbd394c457d1feae342e344f6 (patch)
tree146c10c821977a8af0942cc930d3a4550cf4a624 /win32/mingw.c
parent7d639339e0c46311f8873d560e6f168e71473cd9 (diff)
downloadbusybox-w32-6059723900f2af1fbd394c457d1feae342e344f6.tar.gz
busybox-w32-6059723900f2af1fbd394c457d1feae342e344f6.tar.bz2
busybox-w32-6059723900f2af1fbd394c457d1feae342e344f6.zip
win32: handle Unix-style absolute paths for executables
As noted in commit 548ec7045 (win32: interpret absolute paths as relative to %SYSTEMDRIVE%) a path starting with a '/' in the Unix world is treated as relative to the current drive by Windows. To avoid ambiguity that commit considered certain such paths to be relative to %SYSTEMDRIVE%. Extend this to paths representing executables. Add the functions need_system_drive() and auto_add_system_drive() to detect the need for a system drive prefix and to add it if necessary. Use these functions in: - the 'which' applet - the find_executable() function - tab-completion code - PATH look-up, shellexec(), describe_command() and find_command() in ash - parse_interpreter() and mingw_spawn_1() With these changes executable paths starting with a slash are handled consistently, whatever the current drive.
Diffstat (limited to 'win32/mingw.c')
-rw-r--r--win32/mingw.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 8501ecdd4..e63ffa0ac 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1698,6 +1698,21 @@ const char *get_system_drive(void)
1698 return drive; 1698 return drive;
1699} 1699}
1700 1700
1701/* Return pointer to system drive if path is of form '/file', else NULL */
1702const char *need_system_drive(const char *path)
1703{
1704 if (root_len(path) == 0 && (path[0] == '/' || path[0] == '\\'))
1705 return get_system_drive();
1706 return NULL;
1707}
1708
1709/* Add a system drive prefix to 'path' if necessary, else return 'path' */
1710char *auto_add_system_drive(const char *path)
1711{
1712 const char *sd = need_system_drive(path);
1713 return sd ? auto_string(concat_path_file(sd, path)) : (char *)path;
1714}
1715
1701int chdir_system_drive(void) 1716int chdir_system_drive(void)
1702{ 1717{
1703 const char *sd = get_system_drive(); 1718 const char *sd = get_system_drive();