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_prefixsize.c | |
parent | f9940bb7d1a6ce7d7772e8cbdbbd55a321cc5c18 (diff) | |
download | s6-rc-7a6766da53fa06a02d818208c51801dd79e88a54.tar.xz |
Replace suffix with prefix
Diffstat (limited to 'src/libs6rc/s6rc_livedir_prefixsize.c')
-rw-r--r-- | src/libs6rc/s6rc_livedir_prefixsize.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libs6rc/s6rc_livedir_prefixsize.c b/src/libs6rc/s6rc_livedir_prefixsize.c new file mode 100644 index 0000000..daa8481 --- /dev/null +++ b/src/libs6rc/s6rc_livedir_prefixsize.c @@ -0,0 +1,24 @@ +/* ISC license. */ + +#include <string.h> +#include <sys/stat.h> +#include <errno.h> +#include <s6-rc/s6rc-utils.h> + +int s6rc_livedir_prefixsize (char const *live, size_t *n) +{ + struct stat st ; + size_t llen = strlen(live) ; + char sfn[llen + 8] ; + memcpy(sfn, live, llen) ; + memcpy(sfn + llen, "/prefix", 8) ; + if (stat(sfn, &st) < 0) + { + if (errno != ENOENT) return 0 ; + *n = 0 ; + return 1 ; + } + if (!S_ISREG(st.st_mode)) return (errno = EINVAL, 0) ; + *n = st.st_size ; + return 1 ; +} |