From 381b64487199a9edd46e84f7ff134722c3c3bcfc Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 27 Aug 2015 20:15:21 +0000 Subject: More work on s6-rc-update --- src/libs6rc/deps-lib/s6rc | 1 + src/libs6rc/s6rc_sanitize_dir.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/libs6rc/s6rc_sanitize_dir.c (limited to 'src/libs6rc') 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 +#include +#include +#include + +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 ; +} -- cgit v1.2.3