summaryrefslogtreecommitdiff
path: root/src/libs6rc
diff options
context:
space:
mode:
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 ;
+}