+ /*
+ * 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);
+ }
+
+ /* Resolve partially our path */
+ absolute_path = utils_partial_realpath(absolute_path,
+ absolute_path, PATH_MAX);
+
+ /* As long as we find '/./' in the working_path string */
+ while ((next = strstr(absolute_path, "/./"))) {
+
+ /* We prepare the start_path not containing it */
+ start_path = strndup(absolute_path, next - absolute_path);
+
+ /* And we concatenate it with the part after this string */
+ snprintf(absolute_path, PATH_MAX, "%s%s", start_path, next + 2);
+
+ free(start_path);
+ }
+
+ /* As long as we find '/../' in the working_path string */
+ while ((next = strstr(absolute_path, "/../"))) {
+ /* We find the last level of directory */
+ previous = absolute_path;
+ while ((slash = strpbrk(previous, "/")) && slash != next) {
+ previous = slash + 1;
+ }
+
+ /* Then we prepare the start_path not containing it */
+ start_path = strndup(absolute_path, previous - absolute_path);
+
+ /* And we concatenate it with the part after the '/../' */
+ snprintf(absolute_path, PATH_MAX, "%s%s", start_path, next + 4);
+
+ /* We can free the memory used for the start path*/
+ free(start_path);