aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-03-23 08:38:21 +0000
committerRon Yorston <rmy@pobox.com>2019-03-23 08:38:21 +0000
commit578e943afcd9c818f969502a94375b1a70548bf9 (patch)
treef202f7ae8d81109e6c87ab4422eb5c6ece3f2ed3 /shell
parenta8c63f25b3a8d4b8c9e12b8f6db65c61596da602 (diff)
downloadbusybox-w32-578e943afcd9c818f969502a94375b1a70548bf9.tar.gz
busybox-w32-578e943afcd9c818f969502a94375b1a70548bf9.tar.bz2
busybox-w32-578e943afcd9c818f969502a94375b1a70548bf9.zip
win32: share code to find root prefix of path
Move unc_root_len() from ash to mingw32.c and use it in the new function root_len(), which can be used in make_directory(). This reduces changes to upstream code and saves a few bytes.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/shell/ash.c b/shell/ash.c
index cd6196640..34ddc14f1 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -2860,34 +2860,6 @@ cdopt(void)
2860 return flags; 2860 return flags;
2861} 2861}
2862 2862
2863#if ENABLE_PLATFORM_MINGW32
2864#define is_path_sep(x) ((x) == '/' || (x) == '\\')
2865#define is_unc_path(x) (is_path_sep(x[0]) && is_path_sep(x[1]))
2866#define is_root(x) (is_path_sep(x[0]) && x[1] == '\0')
2867
2868/* Return the length of the root of a UNC path, i.e. the '//host/share'
2869 * component, or 0 if the path doesn't look like that. */
2870static int
2871unc_root_len(const char *dir)
2872{
2873 const char *s = dir + 2;
2874 int len;
2875
2876 if (!is_unc_path(dir))
2877 return 0;
2878 len = strcspn(s, "/\\");
2879 if (len == 0)
2880 return 0;
2881 s += len + 1;
2882 len = strcspn(s, "/\\");
2883 if (len == 0)
2884 return 0;
2885 s += len;
2886
2887 return s - dir;
2888}
2889#endif
2890
2891/* 2863/*
2892 * Update curdir (the name of the current directory) in response to a 2864 * Update curdir (the name of the current directory) in response to a
2893 * cd command. 2865 * cd command.
@@ -2896,6 +2868,8 @@ static const char *
2896updatepwd(const char *dir) 2868updatepwd(const char *dir)
2897{ 2869{
2898#if ENABLE_PLATFORM_MINGW32 2870#if ENABLE_PLATFORM_MINGW32
2871# define is_path_sep(x) ((x) == '/' || (x) == '\\')
2872# define is_root(x) (is_path_sep(x[0]) && x[1] == '\0')
2899 /* 2873 /*
2900 * Due to Windows drive notion, getting pwd is a completely 2874 * Due to Windows drive notion, getting pwd is a completely
2901 * different thing. Handle it in a separate routine 2875 * different thing. Handle it in a separate routine