#17 fixed relative path generation with root path

This commit is contained in:
Leonard Iklé committed 2020-11-26 11:13:34 +01:00
1 parent 2ca7464c89
commit c5addcfc44
3 files changed
+46

No files matched your search

+2
View File
@@ -185,6 +185,8 @@ if(ENABLE_TESTS)
create_test(DEFAULT relative skip_all)
create_test(DEFAULT relative different_roots)
create_test(DEFAULT relative check)
create_test(DEFAULT relative root_path_unix)
create_test(DEFAULT relative root_path_windows)
create_test(DEFAULT root absolute)
create_test(DEFAULT root unc)
create_test(DEFAULT root device_unc)
+4
View File
@@ -184,10 +184,13 @@ static bool cwk_path_get_first_segment_without_root(const char *path,
// why this has to be done first.
segment->path = path;
segment->segments = segments;
segment->begin = segments;
segment->end = segments;
// Now let's check whether this is an empty string. An empty string has no
// segment it could use.
if (*segments == '\0') {
segment->size = 0;
return false;
}
@@ -197,6 +200,7 @@ static bool cwk_path_get_first_segment_without_root(const char *path,
while (cwk_path_is_separator(segments)) {
++segments;
if (*segments == '\0') {
segment->size = 0;
return false;
}
}
+40
View File
@@ -225,6 +225,46 @@ int relative_relative()
return EXIT_SUCCESS;
}
int relative_root_path_unix()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_UNIX);
length = cwk_path_get_relative("/this/is/path_one", "/", result,
sizeof(result));
if (length != 8) {
return EXIT_FAILURE;
}
if (strcmp(result, "../../..") != 0) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int relative_root_path_windows()
{
char result[FILENAME_MAX];
size_t length;
cwk_path_set_style(CWK_STYLE_WINDOWS);
length = cwk_path_get_relative("C:\\this\\is\\path_one", "C:\\", result,
sizeof(result));
if (length != 8) {
return EXIT_FAILURE;
}
if (strcmp(result, "..\\..\\..") != 0) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int relative_simple()
{
char result[FILENAME_MAX];