summaryrefslogtreecommitdiff
path: root/src/libs6rc/s6rc_livedir_canon.c
blob: db5d3a1884a869326b030a0d94ce07d785cd23ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 ;
}