added support for windows device paths

This commit is contained in:
Leonard Iklé committed 2018-09-03 14:32:49 +02:00
1 parent 2d58a19524
commit 34bd01d3bb
3 files changed
+67 -5

No files matched your search

+3
View File
@@ -121,6 +121,9 @@ create_test(DEFAULT relative different_roots)
create_test(DEFAULT relative check)
create_test(DEFAULT root absolute)
create_test(DEFAULT root unc)
create_test(DEFAULT root device_unc)
create_test(DEFAULT root device_dot)
create_test(DEFAULT root device_question_mark)
create_test(DEFAULT root relative)
create_test(DEFAULT root absolute_drive)
create_test(DEFAULT root relative_drive)
+22 -5
View File
@@ -428,6 +428,11 @@ cwk_path_segment_joined_skip_invisible(struct cwk_segment_joined *sj,
static void cwk_path_get_root_windows(const char *path, size_t *length)
{
const char *c;
bool is_device_path;
// A device path is a path which starts with "\\." or "\\?". A device path can
// be a UNC path as well, in which case it will take up one more segment.
is_device_path = false;
// We can not determine the root if this is an empty string. So we set the
// root to NULL and the length to zero and cancel the whole thing.
@@ -451,10 +456,22 @@ static void cwk_path_get_root_windows(const char *path, size_t *length)
return;
}
// Yes, this is a network path. Skip the previous separator. We will grab
// anything up to the next stop. The next top might be a '\0' or another
// separator. That will be the server name.
// Yes, this is a network or device path. Skip the previous separator. Now
// we need to determine whether this is a device path. We might advance one
// character here if the server name starts with a '?' or a '.', but that's
// fine since we will search for a separator afterwards anyway.
++c;
is_device_path = (*c == '?' || *c == '.') && cwk_path_is_separator(++c);
if (is_device_path) {
// That's a device path, and the root must be either "\\.\" or "\\?\"
// which is 4 characters long. (at least that's how Windows
// GetFullPathName behaves.)
*length = 4;
return;
}
// We will grab anything up to the next stop. The next top might be a '\0'
// or another separator. That will be the server name.
c = cwk_path_find_next_stop(c);
// If this is a separator and not the end of a string we wil have to include
@@ -463,8 +480,8 @@ static void cwk_path_get_root_windows(const char *path, size_t *length)
++c;
}
// We are now skipping the shared folder name, which will end after the next
// stop.
// We are now skipping the shared folder name, which will end after the
// next stop.
c = cwk_path_find_next_stop(c);
// Then there might be a separator at the end. We will include that as well,
+42
View File
@@ -29,6 +29,48 @@ int root_relative_drive()
return EXIT_SUCCESS;
}
int root_device_question_mark()
{
size_t length;
cwk_path_set_style(CWK_STYLE_WINDOWS);
cwk_path_get_root("\\\\?\\mydevice\\test", &length);
if (length != 4) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int root_device_dot()
{
size_t length;
cwk_path_set_style(CWK_STYLE_WINDOWS);
cwk_path_get_root("\\\\.\\mydevice\\test", &length);
if (length != 4) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int root_device_unc()
{
size_t length;
cwk_path_set_style(CWK_STYLE_WINDOWS);
cwk_path_get_root("\\\\.\\UNC\\LOCALHOST\\c$\\temp\\test-file.txt", &length);
if (length != 4) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int root_unc()
{
size_t length;