summaryrefslogtreecommitdiff
path: root/src/libs6dns/s6dns_fmt_domainlist.c
blob: 22d6f7715907277964d24cdeca1bcb96212e2954 (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 <s6-dns/s6dns-domain.h>
#include <s6-dns/s6dns-fmt.h>

size_t s6dns_fmt_domainlist (char *s, size_t max, s6dns_domain_t const *list, unsigned int n, char const *delim, size_t delimlen)
{
  size_t len = 0 ;
  unsigned int i = 0 ;
  for (; i < n ; i++)
  {
    unsigned int r = s6dns_domain_tostring(s + len, max - len, list + i) ;
    if (!r) return 0 ;
    len += r ;
    if (i+1 < n)
    {
      if (len + delimlen > max) return (errno = ENAMETOOLONG, 0) ;
      memcpy(s + len, delim, delimlen) ;
      len += delimlen ;
    }
  }
  return len ;
}