MCPcopy Create free account
hub / github.com/containers/bubblewrap / has_path_prefix

Function has_path_prefix

utils.c:213–244  ·  view source on GitHub ↗

Compares if str has a specific path prefix. This differs from a regular prefix in two ways. First of all there may be multiple slashes separating the path elements, and secondly, if a prefix is matched that has to be en entire path element. For instance /a/prefix matches /a/prefix/foo/bar, but not /a/prefixfoo/bar. */

Source from the content-addressed store, hash-verified

211 path element. For instance /a/prefix matches /a/prefix/foo/bar,
212 but not /a/prefixfoo/bar. */
213bool
214has_path_prefix (const char *str,
215 const char *prefix)
216{
217 while (true)
218 {
219 /* Skip consecutive slashes to reach next path
220 element */
221 while (*str == '/')
222 str++;
223 while (*prefix == '/')
224 prefix++;
225
226 /* No more prefix path elements? Done! */
227 if (*prefix == 0)
228 return true;
229
230 /* Compare path element */
231 while (*prefix != 0 && *prefix != '/')
232 {
233 if (*str != *prefix)
234 return false;
235 str++;
236 prefix++;
237 }
238
239 /* Matched prefix path element,
240 must be entire str path element */
241 if (*str != '/' && *str != 0)
242 return false;
243 }
244}
245
246bool
247path_equal (const char *path1,

Callers 2

parse_mountinfoFunction · 0.85
test_has_path_prefixFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_has_path_prefixFunction · 0.68