From 0d127fbf4bbcd09f36740019ef129851464f8660 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 12 Oct 2021 09:06:35 +0100 Subject: win32: use is_dir_sep() everywhere The is_dir_sep() macro, which has been around since the start of busybox-w32, can be used instead of is_path_sep(). --- shell/ash.c | 19 +++++++++---------- win32/mingw.c | 7 +++---- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/shell/ash.c b/shell/ash.c index 0fa3d4dab..487e477a3 100644 --- a/shell/ash.c +++ b/shell/ash.c @@ -3108,7 +3108,6 @@ static const char * updatepwd(const char *dir) { #if ENABLE_PLATFORM_MINGW32 -# define is_path_sep(x) ((x) == '/' || (x) == '\\') /* * Due to Windows drive notion, getting pwd is a completely * different thing. Handle it in a separate routine @@ -3139,17 +3138,17 @@ updatepwd(const char *dir) enum {ABS_DRIVE, ABS_SHARE, REL_OTHER, REL_ROOT, REL_CWD} target; /* skip multiple leading separators unless dir is a UNC path */ - if (is_path_sep(*dir) && unc_root_len(dir) == 0) { - while (is_path_sep(dir[1])) + if (is_dir_sep(*dir) && unc_root_len(dir) == 0) { + while (is_dir_sep(dir[1])) ++dir; } len = strlen(dir); if (len >= 2 && has_dos_drive_prefix(dir)) - target = len >= 3 && is_path_sep(dir[2]) ? ABS_DRIVE : REL_OTHER; + target = len >= 3 && is_dir_sep(dir[2]) ? ABS_DRIVE : REL_OTHER; else if (unc_root_len(dir) != 0) target = ABS_SHARE; - else if (is_path_sep(*dir)) + else if (is_dir_sep(*dir)) target = REL_ROOT; else target = REL_CWD; @@ -3190,15 +3189,15 @@ updatepwd(const char *dir) new = makestrspace(strlen(dir) + 2, new); lim = (char *)stackblock() + len + 1; - if (!is_path_sep(*dir)) { - if (!is_path_sep(new[-1])) + if (!is_dir_sep(*dir)) { + if (!is_dir_sep(new[-1])) USTPUTC('/', new); - if (new > lim && is_path_sep(*lim)) + if (new > lim && is_dir_sep(*lim)) lim++; } else { USTPUTC('/', new); cdcomppath++; - if (is_path_sep(dir[1]) && !is_path_sep(dir[2])) { + if (is_dir_sep(dir[1]) && !is_dir_sep(dir[2])) { USTPUTC('/', new); cdcomppath++; lim++; @@ -3211,7 +3210,7 @@ updatepwd(const char *dir) if (p[1] == '.' && p[2] == '\0') { while (new > lim) { STUNPUTC(new); - if (is_path_sep(new[-1])) + if (is_dir_sep(new[-1])) break; } break; diff --git a/win32/mingw.c b/win32/mingw.c index b8dd6a511..f4ae60d41 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1874,9 +1874,8 @@ void hide_console(void) } #endif -#define is_path_sep(x) ((x) == '/' || (x) == '\\') -#define is_unc_path(x) (strlen(x) > 4 && is_path_sep(x[0]) && \ - is_path_sep(x[1]) && !is_path_sep(x[2])) +#define is_unc_path(x) (strlen(x) > 4 && is_dir_sep(x[0]) && \ + is_dir_sep(x[1]) && !is_dir_sep(x[2])) /* Return the length of the root of a UNC path, i.e. the '//host/share' * component, or 0 if the path doesn't look like that. */ @@ -2009,7 +2008,7 @@ void fix_path_case(char *path) *path = toupper(*path); } else if (len != 0) { - for (path+=2; !is_path_sep(*path); ++path) { + for (path+=2; !is_dir_sep(*path); ++path) { *path = toupper(*path); } } -- cgit v1.2.3-55-g6feb