summaryrefslogtreecommitdiff
path: root/src/libwpactrl/wpactrl_flags_scan.c
blob: e8eecf5c804cf92efa5e43ec90cf0f468a2b9f4a (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
26
27
28
29
30
/* ISC license. */

#include <errno.h>
#include <skalibs/bytestr.h>
#include <skalibs/error.h>
#include <skalibs/stralloc.h>
#include <bcnm/wpactrl.h>

size_t wpactrl_flags_scan (char const *t, stralloc *sa)
{
  size_t sabase = sa->len ;
  int wasnull = !sa->s ;
  char const *s = t ;
  while (*s == '[')
  {
    size_t pos ;
    pos = str_chr(s, ']') ;
    if (!s[pos]) goto eproto ;
    if (!stralloc_catb(sa, s, pos) || !stralloc_0(sa)) goto err ;
    s += pos + 1 ;
  }
  return s - t ;

 eproto:
  errno = EPROTO ;
 err:
  if (wasnull) stralloc_free(sa) ;
  else sa->len = sabase ;
  return 0 ;
}