aboutsummaryrefslogtreecommitdiff
path: root/win32
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 /win32
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 'win32')
-rw-r--r--win32/mingw.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 0206f6dca..3ee1a2496 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1609,3 +1609,38 @@ void hide_console(void)
1609 } 1609 }
1610} 1610}
1611#endif 1611#endif
1612
1613#define is_path_sep(x) ((x) == '/' || (x) == '\\')
1614#define is_unc_path(x) (is_path_sep(x[0]) && is_path_sep(x[1]))
1615
1616/* Return the length of the root of a UNC path, i.e. the '//host/share'
1617 * component, or 0 if the path doesn't look like that. */
1618int unc_root_len(const char *dir)
1619{
1620 const char *s = dir + 2;
1621 int len;
1622
1623 if (!is_unc_path(dir))
1624 return 0;
1625 len = strcspn(s, "/\\");
1626 if (len == 0)
1627 return 0;
1628 s += len + 1;
1629 len = strcspn(s, "/\\");
1630 if (len == 0)
1631 return 0;
1632 s += len;
1633
1634 return s - dir;
1635}
1636
1637/* Return the length of the root of a path, i.e. either the drive or
1638 * UNC '//host/share', or 0 if the path doesn't look like that. */
1639int root_len(const char *path)
1640{
1641 if (path == NULL)
1642 return 0;
1643 if (isalpha(*path) && path[1] == ':')
1644 return 2;
1645 return unc_root_len(path);
1646}