Return the length of the longest common prefix of canonical PATH1 and PATH2, ensuring only full path components are matched. Return 0 on no match. */
| 26 | of canonical PATH1 and PATH2, ensuring only full path components |
| 27 | are matched. Return 0 on no match. */ |
| 28 | ATTRIBUTE_PURE |
| 29 | static int |
| 30 | path_common_prefix (char const *path1, char const *path2) |
| 31 | { |
| 32 | int i = 0; |
| 33 | int ret = 0; |
| 34 | |
| 35 | /* We already know path1[0] and path2[0] are '/'. Special case |
| 36 | '//', which is only present in a canonical name on platforms |
| 37 | where it is distinct. */ |
| 38 | if ((path1[1] == '/') != (path2[1] == '/')) |
| 39 | return 0; |
| 40 | |
| 41 | while (*path1 && *path2) |
| 42 | { |
| 43 | if (*path1 != *path2) |
| 44 | break; |
| 45 | if (*path1 == '/') |
| 46 | ret = i + 1; |
| 47 | path1++; |
| 48 | path2++; |
| 49 | i++; |
| 50 | } |
| 51 | |
| 52 | if ((!*path1 && !*path2) |
| 53 | || (!*path1 && *path2 == '/') |
| 54 | || (!*path2 && *path1 == '/')) |
| 55 | ret = i; |
| 56 | |
| 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | /* Either output STR to stdout or |
| 61 | if *PBUF is not null then append STR to *PBUF |