summaryrefslogtreecommitdiff
path: root/src/libwpactrl/wpactrl_flags_scan.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-08-04 22:46:45 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-08-04 22:46:45 +0000
commitbabf43abf301d072192bda1f72a47440c354b072 (patch)
treed917d33ebb97d2b783e163f299b360be4f5b3a0a /src/libwpactrl/wpactrl_flags_scan.c
parent69099d84949a8044fdfc74e9d7ff6b9e57fc0bcd (diff)
downloadbcnm-babf43abf301d072192bda1f72a47440c354b072.tar.xz
Add the higher layer of libwpactrl
Diffstat (limited to 'src/libwpactrl/wpactrl_flags_scan.c')
-rw-r--r--src/libwpactrl/wpactrl_flags_scan.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libwpactrl/wpactrl_flags_scan.c b/src/libwpactrl/wpactrl_flags_scan.c
new file mode 100644
index 0000000..e8eecf5
--- /dev/null
+++ b/src/libwpactrl/wpactrl_flags_scan.c
@@ -0,0 +1,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 ;
+}