From b4b2b2c4fbba12561c5e988177bef699be306b26 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 12 Oct 2021 13:43:15 +0100 Subject: win32: rename is_absolute_path() As the comment pointed out is_absolute_path() was misnamed. Rename it to is_relative_path() and change the sense of all tests. --- include/mingw.h | 2 +- libbb/xreadlink.c | 2 +- shell/ash.c | 6 +++--- win32/mingw.c | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/mingw.h b/include/mingw.h index 74a65116c..6ace91470 100644 --- a/include/mingw.h +++ b/include/mingw.h @@ -579,4 +579,4 @@ void make_sparse(int fd, off_t start, off_t end); int skip_ansi_emulation(int reset); int unix_path(const char *path); int has_path(const char *file); -int is_absolute_path(const char *path); +int is_relative_path(const char *path); diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index b64654b33..31680810b 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c @@ -80,7 +80,7 @@ char* FAST_FUNC xmalloc_follow_symlinks(const char *path) } #if ENABLE_PLATFORM_MINGW32 - if (!is_absolute_path(linkpath)) { + if (is_relative_path(linkpath)) { #else if (*linkpath != '/') { #endif diff --git a/shell/ash.c b/shell/ash.c index 487e477a3..9214982c1 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -344,7 +344,7 @@ typedef long arith_t; #endif #if !ENABLE_PLATFORM_MINGW32 -# define is_absolute_path(path) ((path)[0] == '/') +# define is_relative_path(path) ((path)[0] != '/') #endif #if !BB_MMU @@ -3379,7 +3379,7 @@ cdcmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) } if (!dest) dest = nullstr; - if (is_absolute_path(dest)) + if (!is_relative_path(dest)) goto step6; if (*dest == '.') { c = dest[1]; @@ -14728,7 +14728,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) } } /* if rehash, don't redo absolute path names */ - if (is_absolute_path(fullname) && idx <= prev) { + if (!is_relative_path(fullname) && idx <= prev) { if (idx < prev) continue; TRACE(("searchexec \"%s\": no change\n", name)); diff --git a/win32/mingw.c b/win32/mingw.c index f4ae60d41..7ce60139e 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -811,7 +811,7 @@ int utimensat(int fd, const char *path, const struct timespec times[2], HANDLE fh; DWORD cflag = FILE_FLAG_BACKUP_SEMANTICS; - if (!is_absolute_path(path) && fd != AT_FDCWD) { + if (is_relative_path(path) && fd != AT_FDCWD) { errno = ENOSYS; // partial implementation return rc; } @@ -1202,7 +1202,7 @@ int symlink(const char *target, const char *linkpath) return -1; } - if (!is_absolute_path(target) && has_path(linkpath)) { + if (is_relative_path(target) && has_path(linkpath)) { /* make target's path relative to current directory */ const char *name = bb_get_last_path_component_nostrip(linkpath); relative = xasprintf("%.*s%s", @@ -2082,11 +2082,11 @@ int has_path(const char *file) has_dos_drive_prefix(file); } -/* This function is misnamed. It's actually a test for 'is not a path - * relative to the current working directory'. On Unix this is the - * same as 'is an absolute path' but Windows also has paths relative to - * current root and relative to current directory of another drive. */ -int is_absolute_path(const char *path) +/* Test whether a path is relative to a known location (usually the + * current working directory or a symlink). On Unix this is a path + * that doesn't start with a slash but on Windows we also need to + * exclude paths that start with a backslash or a drive letter. */ +int is_relative_path(const char *path) { - return path[0] == '/' || path[0] == '\\' || has_dos_drive_prefix(path); + return !is_dir_sep(path[0]) && !has_dos_drive_prefix(path); } -- cgit v1.2.3-55-g6feb