summaryrefslogtreecommitdiff
path: root/src/serverlib/s6rc_livedir_prefix.c
blob: 09fe263b752270da4c50de0ec2ea99ebb6009eac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* 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) ;
  ssize_t r ;
  char sfn[llen + 8] ;
  memcpy(sfn, live, llen) ;
  memcpy(sfn + llen, "/prefix", 8) ;
  r = openreadnclose(sfn, s, n) ;
  if (r < 0) return errno == ENOENT ? 0 : r ;
  if (memchr(s, '/', r) || memchr(s, '\n', r)) return (errno = EINVAL, -1) ;
  return r ;
}