summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2013-07-10 12:59:12 -0400
committerAnthony G. Basile <blueness@gentoo.org>2013-07-10 12:59:18 -0400
commitae66dd92e559c71a2100a4fbf2a4779f39859d10 (patch)
tree707d30d20af3c310ba063e9bbee6146748117149 /src
parent7a2e1b14095ecfdf092313c7ea36a9831d9e384a (diff)
src/udev/mkdir.c: import path_startswith() from upstream
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/udev/mkdir.c34
-rw-r--r--src/udev/mkdir.h1
2 files changed, 35 insertions, 0 deletions
diff --git a/src/udev/mkdir.c b/src/udev/mkdir.c
index c775bfa0c3..420a9eb1b8 100644
--- a/src/udev/mkdir.c
+++ b/src/udev/mkdir.c
@@ -39,6 +39,40 @@ static int is_dir(const char* path) {
return S_ISDIR(st.st_mode);
}
+
+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;
+ }
+}
+
static int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, bool apply) {
const char *p, *e;
int r;
diff --git a/src/udev/mkdir.h b/src/udev/mkdir.h
index db3141ef59..24ffa6364c 100644
--- a/src/udev/mkdir.h
+++ b/src/udev/mkdir.h
@@ -22,6 +22,7 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+char* path_startswith(const char *path, const char *prefix) _pure_;
int mkdir_parents(const char *path, mode_t mode);
int mkdir_parents_label(const char *path, mode_t mode);
int mkdir_p(const char *path, mode_t mode);