| 782 | | |
| 783 | | /* first attempt to collapse the pathname */ |
| 784 | | while (*p) |
| 785 | | { |
| 786 | | if (*p == '/' && p[1] == '/') |
| 787 | | { |
| 788 | | *q++ = '/'; |
| 789 | | p += 2; |
| 790 | | } |
| 791 | | else if (p[0] == '/' && p[1] == '.' && p[2] == '/') |
| 792 | | { |
| 793 | | *q++ = '/'; |
| 794 | | p += 3; |
| 795 | | } |
| 796 | | else |
| 797 | | *q++ = *p++; |
| 798 | | } |
| 799 | | *q = 0; |
| | 783 | |
| | 784 | /* cleanup path */ |
| | 785 | if (strstr (p, "//") || strstr (p, "/./")) |
| | 786 | { |
| | 787 | /* first attempt to collapse the pathname, this is more |
| | 788 | * lightweight than realpath() and doesn't resolve links |
| | 789 | */ |
| | 790 | while (*p) |
| | 791 | { |
| | 792 | if (*p == '/' && p[1] == '/') |
| | 793 | { |
| | 794 | *q++ = '/'; |
| | 795 | p += 2; |
| | 796 | } |
| | 797 | else if (p[0] == '/' && p[1] == '.' && p[2] == '/') |
| | 798 | { |
| | 799 | *q++ = '/'; |
| | 800 | p += 3; |
| | 801 | } |
| | 802 | else |
| | 803 | *q++ = *p++; |
| | 804 | } |
| | 805 | *q = 0; |
| | 806 | } |
| | 807 | else if (strstr (p, "..") && |
| | 808 | (scheme == U_UNKNOWN || scheme == U_FILE) && |
| | 809 | realpath (p, tmp)) |
| | 810 | strfcpy (p, tmp, buflen - (p - s)); |