diff options
Diffstat (limited to 'src/serverlib/s6rc_livedir_prefixsize.c')
-rw-r--r-- | src/serverlib/s6rc_livedir_prefixsize.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/serverlib/s6rc_livedir_prefixsize.c b/src/serverlib/s6rc_livedir_prefixsize.c new file mode 100644 index 0000000..d897fe6 --- /dev/null +++ b/src/serverlib/s6rc_livedir_prefixsize.c @@ -0,0 +1,26 @@ +/* ISC license. */ + +#include <limits.h> +#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) ; + if (st.st_size > PATH_MAX) return (errno = ENAMETOOLONG, 0) ; + *n = st.st_size ; + return 1 ; +} |