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

Function path_prefix

src/realpath.c:130–156  ·  view source on GitHub ↗

Test whether canonical prefix is parent or match of path. */

Source from the content-addressed store, hash-verified

128
129/* Test whether canonical prefix is parent or match of path. */
130ATTRIBUTE_PURE
131static bool
132path_prefix (char const *prefix, char const *path)
133{
134 /* We already know prefix[0] and path[0] are '/'. */
135 prefix++;
136 path++;
137
138 /* '/' is the prefix of everything except '//' (since we know '//'
139 is only present after canonicalization if it is distinct). */
140 if (!*prefix)
141 return *path != '/';
142
143 /* Likewise, '//' is a prefix of any double-slash path. */
144 if (*prefix == '/' && !prefix[1])
145 return *path == '/';
146
147 /* Any other prefix has a non-slash portion. */
148 while (*prefix && *path)
149 {
150 if (*prefix != *path)
151 break;
152 prefix++;
153 path++;
154 }
155 return (!*prefix && (*path == '/' || !*path));
156}
157
158static bool
159isdir (char const *path)

Callers 2

process_pathFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected