- /* Split part that will be resolved by realpath (relative path from
- * current directory using ./ or ../ only) and part that could not
- * (directory names)
- */
- while ((next = strpbrk(end_path, "/")) && (next != last_char)) {
- end_path = next + 1;
- if (strncmp(end_path, "./", 2) != 0 &&
- strncmp(end_path, "../", 3) != 0) {
- break;
- }
- }
-
- /* If this is the end of the string, and we still can resolve it */
- if (strncmp(end_path, "..\0", 3) == 0 ||
- strncmp(end_path, ".\0", 2) == 0) {
- end_path += strlen(end_path);
- }
-
- /* If the end part is the whole path, we are in the current dir */
- if (end_path == path) {
- cut_path = strdup(".");
- /* Else, cut the resolvable part from original path */
- } else {
- cut_path = strndup(path, end_path - path);
- }
+ /* If it was a reference to parent directory, go back one more time */
+ if (is_dotdot) {
+ last_token = strrchr(absolute_path, '/');