diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2014-08-14 18:12:43 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-08-14 18:12:43 -0400 |
commit | 03070edd5c0f6ae55ed79b9fc1295af39844ff40 (patch) | |
tree | 047bc4cd7ebdb01cc4d6aa0bfb111ec5ce73f313 /src/shared/path-util.c | |
parent | 28744043fbaca39dfc9fd1666a8557fd6d8a690f (diff) |
src/shared: import more code cleanups from upstream
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared/path-util.c')
-rw-r--r-- | src/shared/path-util.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/shared/path-util.c b/src/shared/path-util.c index 783d130842..2a2f33dbca 100644 --- a/src/shared/path-util.c +++ b/src/shared/path-util.c @@ -248,6 +248,39 @@ char *path_kill_slashes(char *path) { return path; } +char* path_startswith(const char *path, const char *prefix) { + assert(path); + assert(prefix); + + if ((path[0] == '/') != (prefix[0] == '/')) + return NULL; + + for (;;) { + size_t a, b; + + path += strspn(path, "/"); + prefix += strspn(prefix, "/"); + + if (*prefix == 0) + return (char*) path; + + if (*path == 0) + return NULL; + + a = strcspn(path, "/"); + b = strcspn(prefix, "/"); + + if (a != b) + return NULL; + + if (memcmp(path, prefix, a) != 0) + return NULL; + + path += a; + prefix += b; + } +} + bool path_equal(const char *a, const char *b) { assert(a); assert(b); |