diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2024-07-05 18:40:15 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2024-07-05 18:40:15 +0000 |
commit | d3a944d70ef6b07753659aabe237168f91473fc8 (patch) | |
tree | 2a1a8db4a692a8b203a4f6d5a00ad594dcc9ad97 /src/libs6rc/s6rc_livedir_canon.c | |
parent | 398133d1553522d1acc1a070644c42d17f22709f (diff) | |
download | s6-rc-d3a944d70ef6b07753659aabe237168f91473fc8.tar.xz |
Prepare for 0.5.5.0; add s6rc_livedir_canon
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6rc/s6rc_livedir_canon.c')
-rw-r--r-- | src/libs6rc/s6rc_livedir_canon.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libs6rc/s6rc_livedir_canon.c b/src/libs6rc/s6rc_livedir_canon.c new file mode 100644 index 0000000..db5d3a1 --- /dev/null +++ b/src/libs6rc/s6rc_livedir_canon.c @@ -0,0 +1,25 @@ +/* ISC license. */ + +#include <string.h> +#include <errno.h> + +#include <skalibs/alloc.h> + +#include <s6-rc/s6rc-utils.h> + +int s6rc_livedir_canon (char const **live) +{ + size_t llen = strlen(*live) ; + size_t n = llen ; + while (n && (*live)[n - 1] == '/') --n ; + if (!n) return (errno = EINVAL, 0) ; + if (n < llen) + { + char *x = alloc(n + 1) ; + if (!x) return 0 ; + memcpy(x, *live, n) ; + x[n] = 0 ; + *live = x ; + } + return 1 ; +} |