diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-10-09 10:38:37 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-10-09 10:38:37 +0000 |
commit | 7a6766da53fa06a02d818208c51801dd79e88a54 (patch) | |
tree | 1378bbe390e9cd8077f75efdd6ac1ee79be0bf80 /src/libs6rc/s6rc_livedir_prefix.c | |
parent | f9940bb7d1a6ce7d7772e8cbdbbd55a321cc5c18 (diff) | |
download | s6-rc-7a6766da53fa06a02d818208c51801dd79e88a54.tar.xz |
Replace suffix with prefix
Diffstat (limited to 'src/libs6rc/s6rc_livedir_prefix.c')
-rw-r--r-- | src/libs6rc/s6rc_livedir_prefix.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/libs6rc/s6rc_livedir_prefix.c b/src/libs6rc/s6rc_livedir_prefix.c new file mode 100644 index 0000000..18a95fe --- /dev/null +++ b/src/libs6rc/s6rc_livedir_prefix.c @@ -0,0 +1,20 @@ +/* ISC license. */ + +#include <string.h> +#include <errno.h> +#include <skalibs/djbunix.h> +#include <s6-rc/s6rc-utils.h> + +ssize_t s6rc_livedir_prefix (char const *live, char *s, size_t n) +{ + size_t llen = strlen(live) ; + size_t r ; + char sfn[llen + 8] ; + memcpy(sfn, live, llen) ; + memcpy(sfn + llen, "/prefix", 8) ; + r = openreadnclose(sfn, s, n) ; + if (r < 0) return r ; + if (memchr(s, '/', r) || memchr(s, '\n', r)) + return (errno = EINVAL, -1) ; + return r ; +} |