MCPcopy Create free account
hub / github.com/coreutils/coreutils / path_common_prefix

Function path_common_prefix

src/relpath.c:28–58  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

26 of canonical PATH1 and PATH2, ensuring only full path components
27 are matched. Return 0 on no match. */
28ATTRIBUTE_PURE
29static int
30path_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

Callers 1

relpathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected