// Reset the data structure
path->segments = NULL;
path->num_segments = 0;
+ path->is_absolute = 0;
}
static void pakfire_path_free(struct pakfire_path* path) {
// Is the path absolute?
if (*s == '/') {
- path->is_absolute = 1;
-
// If we are joining strings and the new string is absolute,
// we throw away all segments.
pakfire_path_free_segments(path);
+
+ path->is_absolute = 1;
}
// Copy path into buffer
return -ENOBUFS;
// Return / for empty paths
- if (!path->num_segments)
- return __pakfire_string_set(buffer, length, "/");
+ if (!path->num_segments) {
+ if (path->is_absolute)
+ return __pakfire_string_set(buffer, length, "/");
+ else
+ return __pakfire_string_set(buffer, length, "");
+ }
for (unsigned int i = 0; i < path->num_segments; i++) {
s = path->segments[i];
// Add separator
- *p++ = '/';
+ if (i > 0 || path->is_absolute)
+ *p++ = '/';
// Add the segment
while (*s)