aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2022-02-15 10:26:25 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2022-02-15 10:26:25 -0500
commit15ba3bc645c7620cdbaf261f8ba4634cd2a932a0 (patch)
tree0a7d80e737ca50fa58fc9d4d20eef34caf023d35
parent0a6e4e584686422ec777e9448668e4c02a30c23c (diff)
downloadcleanpath-15ba3bc645c7620cdbaf261f8ba4634cd2a932a0.tar.gz
Strip trailing separators
-rw-r--r--lib/cleanpath.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/cleanpath.c b/lib/cleanpath.c
index 138251f..5f7db0e 100644
--- a/lib/cleanpath.c
+++ b/lib/cleanpath.c
@@ -109,22 +109,24 @@ char *cleanpath_read(struct CleanPath *path) {
goto cleanpath_read__failure;
}
- for (part_count = 0; part_count < CLEANPATH_PART_MAX && path->part[part_count] != NULL; part_count++);
+ for (part_count = 0; path->part[part_count] != NULL; part_count++) {
+ if (!strlen(path->part[part_count]))
+ continue;
+ }
- for (size_t i = 0; i < CLEANPATH_PART_MAX && path->part[i] != NULL; i++) {
+ for (size_t i = 0; i < part_count; i++) {
// Ignore filtered paths
- if (*path->part[i] == '\0') {
+ if (!strlen(path->part[i])) {
continue;
}
strcat(result, path->part[i]);
- if (part_count > 1 && i == 0) {
+ if (i == part_count - 1)
continue;
- }
strcat(result, path->sep);
}
result_len = strlen(result);
- if (result_len) {
+ if (result_len && !strcmp(&result[result_len - 1], path->sep)) {
result[result_len - 1] = '\0';
}