summaryrefslogtreecommitdiff
path: root/src/libs6rc
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-08-27 20:15:21 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-08-27 20:15:21 +0000
commit381b64487199a9edd46e84f7ff134722c3c3bcfc (patch)
treec7b08bd79c25cb1153b300d4d0cb5743ab1d1454 /src/libs6rc
parent8d9bb38022b9282128e5ddbfa8f62f9023a8698b (diff)
downloads6-rc-381b64487199a9edd46e84f7ff134722c3c3bcfc.tar.xz
More work on s6-rc-update
Diffstat (limited to 'src/libs6rc')
-rw-r--r--src/libs6rc/deps-lib/s6rc1
-rw-r--r--src/libs6rc/s6rc_sanitize_dir.c26
2 files changed, 27 insertions, 0 deletions
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc
index cedae10..1ee4dfb 100644
--- a/src/libs6rc/deps-lib/s6rc
+++ b/src/libs6rc/deps-lib/s6rc
@@ -6,6 +6,7 @@ s6rc_db_read_sizes.o
s6rc_db_read_uint32.o
s6rc_graph_closure.o
s6rc_read_uint.o
+s6rc_sanitize_dir.o
s6rc_servicedir_internal.o
s6rc_servicedir_block.o
s6rc_servicedir_unblock.o
diff --git a/src/libs6rc/s6rc_sanitize_dir.c b/src/libs6rc/s6rc_sanitize_dir.c
new file mode 100644
index 0000000..69c4d13
--- /dev/null
+++ b/src/libs6rc/s6rc_sanitize_dir.c
@@ -0,0 +1,26 @@
+/* ISC license. */
+
+#include <skalibs/bytestr.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
+#include <s6-rc/s6rc-utils.h>
+
+int s6rc_sanitize_dir (stralloc *sa, char const *fn, unsigned int *dirlen)
+{
+ int wasnull = !sa->s ;
+ unsigned int base = sa->len ;
+ unsigned int fnlen = str_len(fn) ;
+ unsigned int ddirlen ;
+ if (!sadirname(sa, fn, fnlen)) return 0 ;
+ if (sa->len != base + 1 || sa->s[base] != '/')
+ if (!stralloc_catb(sa, "/", 1)) goto err ;
+ ddirlen = sa->len ;
+ if (!sabasename(sa, fn, fnlen)) goto err ;
+ *dirlen = ddirlen ;
+ return 1 ;
+
+ err:
+ if (wasnull) stralloc_free(sa) ;
+ else sa->len = base ;
+ return 0 ;
+}