1 /* vi: set sw=4 ts=4: */
3 * bb_simplify_path implementation for busybox
5 * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
12 char *bb_simplify_path(const char *path)
17 start = xstrdup(path);
20 start = concat_path_file(s, path);
27 if (*s == '/') { /* skip duplicate (or initial) slash */
29 } else if (*s == '.') {
30 if (s[1] == '/' || s[1] == 0) { /* remove extra '.' */
32 } else if ((s[1] == '.') && (s[2] == '/' || s[2] == 0)) {
35 while (*--p != '/'); /* omit previous dir */
44 if ((p == start) || (*p != '/')) { /* not a trailing slash */
45 ++p; /* so keep last character */