- /* Find last token delimited by '/' */
- while ((next = strpbrk(end_path + 1, "/"))) {
- end_path = next;
+ /* Allocate memory for the absolute_path */
+ absolute_path = zmalloc(PATH_MAX);
+ if (absolute_path == NULL) {
+ PERROR("zmalloc expand path");
+ goto error;
+ }
+
+ /*
+ * If the path is not already absolute nor explicitly relative,
+ * consider we're in the current directory
+ */
+ if (*path != '/' && strncmp(path, "./", 2) != 0 &&
+ strncmp(path, "../", 3) != 0) {
+ snprintf(absolute_path, PATH_MAX, "./%s", path);
+ /* Else, we just copy the path */
+ } else {
+ strncpy(absolute_path, path, PATH_MAX);