aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2023-10-04 09:09:49 +0100
committerRon Yorston <rmy@pobox.com>2023-10-04 09:09:49 +0100
commit199687610d3bf1b29b7342da40d9306dd46accdc (patch)
tree66343fec19b9ca730c1c162718cff07d386d70e7
parent1942077cade6374a7c37fcdcf6cbf55dd52e13c4 (diff)
downloadbusybox-w32-199687610d3bf1b29b7342da40d9306dd46accdc.tar.gz
busybox-w32-199687610d3bf1b29b7342da40d9306dd46accdc.tar.bz2
busybox-w32-199687610d3bf1b29b7342da40d9306dd46accdc.zip
win32: fix handling of relative paths
Commit 548ec7045b (win32: interpret absolute paths as relative to %SYSTEMDRIVE%) introduced the function xabsolute_path() to make relative paths absolute. This is used in 'dkpg' and 'man' to avoid having to tinker with absolute paths from upstream. Unfortunately, it's too eager to use the relative path. This results in dpkg failing to install deb files with a relative path. Saves 32-48 bytes. (GitHub issue #371)
-rw-r--r--win32/mingw.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 8588b1a86..977848a2a 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -2292,28 +2292,19 @@ int chdir_system_drive(void)
2292 * This function is used to make relative paths absolute before a call 2292 * This function is used to make relative paths absolute before a call
2293 * to chdir_system_drive(). It's unlikely to be useful in other cases. 2293 * to chdir_system_drive(). It's unlikely to be useful in other cases.
2294 * 2294 *
2295 * If the argument is an absolute path or a relative path which resolves 2295 * If the argument is an absolute path return 'path', otherwise return
2296 * to a path on the system drive return 'path'. If it's a relative path 2296 * an allocated string containing the resolved path. Die on failure,
2297 * which resolves to a path that isn't on the system drive return an
2298 * allocated string containing the resolved path. Die on failure,
2299 * which is most likely because the file doesn't exist. 2297 * which is most likely because the file doesn't exist.
2300 */ 2298 */
2301char *xabsolute_path(char *path) 2299char *xabsolute_path(char *path)
2302{ 2300{
2303 char *rpath; 2301 char *rpath;
2304 const char *sd;
2305 2302
2306 if (root_len(path) != 0) 2303 if (root_len(path) != 0)
2307 return path; // absolute path 2304 return path; // absolute path
2308 rpath = xmalloc_realpath(path); 2305 rpath = xmalloc_realpath(path);
2309 if (rpath) { 2306 if (rpath)
2310 sd = get_system_drive();
2311 if (sd && is_prefixed_with_case(rpath, sd)) {
2312 free(rpath);
2313 return path; // resolved path is on system drive
2314 }
2315 return rpath; 2307 return rpath;
2316 }
2317 bb_perror_msg_and_die("can't open '%s'", path); 2308 bb_perror_msg_and_die("can't open '%s'", path);
2318} 2309}
2319 2310