aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2021-05-07 18:27:17 -0400
committerGitHub <noreply@github.com>2021-05-07 18:27:17 -0400
commitd0e3a85d09eb43c5de821dded7fc4aa76f593d2d (patch)
tree0f35d7d1ea267cccec6e476ed1eb3c010927c653 /lib
parentb072d93e47949c9729c979fceef8a7c7bfd22d39 (diff)
downloadcleanpath-d0e3a85d09eb43c5de821dded7fc4aa76f593d2d.tar.gz
Testing (#5)
* Fix separators appearing at the end once and for all * Add cleanpath executable tests * Escape slashes * Enable verbose testing
Diffstat (limited to 'lib')
-rw-r--r--lib/cleanpath.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/cleanpath.c b/lib/cleanpath.c
index fdb615d..c3a7e81 100644
--- a/lib/cleanpath.c
+++ b/lib/cleanpath.c
@@ -103,6 +103,7 @@ void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern
*/
char *cleanpath_read(struct CleanPath *path) {
char *result;
+ size_t result_len;
result = calloc(path->data_len, sizeof(char));
if (result == NULL) {
@@ -115,11 +116,12 @@ char *cleanpath_read(struct CleanPath *path) {
continue;
}
strcat(result, path->part[i]);
+ strcat(result, path->sep);
+ }
- // Do not append path separator on final element
- if (path->part[i + 1] != NULL && *path->part[i + 1] != '\0') {
- strcat(result, path->sep);
- }
+ result_len = strlen(result);
+ if (result_len) {
+ result[result_len - 1] = '\0';
}
cleanpath_read__failure: