join.py: Add Replica-Locations for DomainDNS and ForestDNS
[Samba.git] / lib / util / strv_util.c
blob5c914e5620bf78012a6c85b216be88bdcb63e8fb
1 /*
2 * strv-based utilities
4 * Copyright Martin Schwenke <martin@meltin.net> 2016
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <string.h>
21 #include <talloc.h>
23 #include "replace.h"
24 #include "strv.h"
26 #include "strv_util.h"
28 int strv_split(TALLOC_CTX *mem_ctx, char **strv,
29 const char *src, const char *sep)
31 const char *s;
33 if (src == NULL) {
34 return 0;
37 s = src;
38 while (*s != '\0') {
39 size_t len;
41 /* Skip separators */
42 len = strspn(s, sep);
43 if (len != 0) {
44 s += len;
47 /* Find non-separator substring */
48 len = strcspn(s, sep);
49 if (len != 0) {
50 int ret = strv_addn(mem_ctx, strv, s, len);
51 if (ret != 0) {
52 TALLOC_FREE(*strv);
53 return ret;
55 s += len;
59 return 0;