mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
util: Split str_list_make_v3() into separate file
str_list_make_v3() calls next_token_talloc(), which has deep dependencies, so can't be used without dragging in a lot of code. The other functions in this file are generally useful and have minimal dependencies. So leave the easily reusable code and split out the more difficult stuff. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
parent
aec07b8b60
commit
c4c1592408
@ -513,85 +513,3 @@ _PUBLIC_ const char **str_list_copy_const(TALLOC_CTX *mem_ctx,
|
|||||||
ret[i] = NULL;
|
ret[i] = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Needed for making an "unconst" list "const"
|
|
||||||
*/
|
|
||||||
_PUBLIC_ const char **const_str_list(char **list)
|
|
||||||
{
|
|
||||||
return discard_const_p(const char *, list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* str_list_make, v3 version. The v4 version does not
|
|
||||||
* look at quoted strings with embedded blanks, so
|
|
||||||
* do NOT merge this function please!
|
|
||||||
*/
|
|
||||||
#define S_LIST_ABS 16 /* List Allocation Block Size */
|
|
||||||
|
|
||||||
char **str_list_make_v3(TALLOC_CTX *mem_ctx, const char *string,
|
|
||||||
const char *sep)
|
|
||||||
{
|
|
||||||
char **list;
|
|
||||||
const char *str;
|
|
||||||
char *s, *tok;
|
|
||||||
int num, lsize;
|
|
||||||
|
|
||||||
if (!string || !*string)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
list = talloc_array(mem_ctx, char *, S_LIST_ABS+1);
|
|
||||||
if (list == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
lsize = S_LIST_ABS;
|
|
||||||
|
|
||||||
s = talloc_strdup(list, string);
|
|
||||||
if (s == NULL) {
|
|
||||||
DEBUG(0,("str_list_make: Unable to allocate memory"));
|
|
||||||
TALLOC_FREE(list);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (!sep) sep = LIST_SEP;
|
|
||||||
|
|
||||||
num = 0;
|
|
||||||
str = s;
|
|
||||||
|
|
||||||
while (next_token_talloc(list, &str, &tok, sep)) {
|
|
||||||
|
|
||||||
if (num == lsize) {
|
|
||||||
char **tmp;
|
|
||||||
|
|
||||||
lsize += S_LIST_ABS;
|
|
||||||
|
|
||||||
tmp = talloc_realloc(mem_ctx, list, char *,
|
|
||||||
lsize + 1);
|
|
||||||
if (tmp == NULL) {
|
|
||||||
DEBUG(0,("str_list_make: "
|
|
||||||
"Unable to allocate memory"));
|
|
||||||
TALLOC_FREE(list);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
list = tmp;
|
|
||||||
|
|
||||||
memset (&list[num], 0,
|
|
||||||
((sizeof(char*)) * (S_LIST_ABS +1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
list[num] = tok;
|
|
||||||
num += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
list[num] = NULL;
|
|
||||||
|
|
||||||
TALLOC_FREE(s);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char **str_list_make_v3_const(TALLOC_CTX *mem_ctx,
|
|
||||||
const char *string,
|
|
||||||
const char *sep)
|
|
||||||
{
|
|
||||||
return const_str_list(str_list_make_v3(mem_ctx, string, sep));
|
|
||||||
}
|
|
||||||
|
112
lib/util/util_strlist_v3.c
Normal file
112
lib/util/util_strlist_v3.c
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
Unix SMB/CIFS implementation.
|
||||||
|
|
||||||
|
Copyright (C) Andrew Tridgell 2005
|
||||||
|
Copyright (C) Jelmer Vernooij 2005
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "includes.h"
|
||||||
|
#include "system/locale.h"
|
||||||
|
#include "lib/util/tsort.h"
|
||||||
|
|
||||||
|
#undef strcasecmp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief String list manipulation v3
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needed for making an "unconst" list "const"
|
||||||
|
*/
|
||||||
|
_PUBLIC_ const char **const_str_list(char **list)
|
||||||
|
{
|
||||||
|
return discard_const_p(const char *, list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* str_list_make, v3 version. The v4 version does not
|
||||||
|
* look at quoted strings with embedded blanks, so
|
||||||
|
* do NOT merge this function please!
|
||||||
|
*/
|
||||||
|
#define S_LIST_ABS 16 /* List Allocation Block Size */
|
||||||
|
|
||||||
|
char **str_list_make_v3(TALLOC_CTX *mem_ctx, const char *string,
|
||||||
|
const char *sep)
|
||||||
|
{
|
||||||
|
char **list;
|
||||||
|
const char *str;
|
||||||
|
char *s, *tok;
|
||||||
|
int num, lsize;
|
||||||
|
|
||||||
|
if (!string || !*string)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
list = talloc_array(mem_ctx, char *, S_LIST_ABS+1);
|
||||||
|
if (list == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
lsize = S_LIST_ABS;
|
||||||
|
|
||||||
|
s = talloc_strdup(list, string);
|
||||||
|
if (s == NULL) {
|
||||||
|
DEBUG(0,("str_list_make: Unable to allocate memory"));
|
||||||
|
TALLOC_FREE(list);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!sep) sep = LIST_SEP;
|
||||||
|
|
||||||
|
num = 0;
|
||||||
|
str = s;
|
||||||
|
|
||||||
|
while (next_token_talloc(list, &str, &tok, sep)) {
|
||||||
|
|
||||||
|
if (num == lsize) {
|
||||||
|
char **tmp;
|
||||||
|
|
||||||
|
lsize += S_LIST_ABS;
|
||||||
|
|
||||||
|
tmp = talloc_realloc(mem_ctx, list, char *,
|
||||||
|
lsize + 1);
|
||||||
|
if (tmp == NULL) {
|
||||||
|
DEBUG(0,("str_list_make: "
|
||||||
|
"Unable to allocate memory"));
|
||||||
|
TALLOC_FREE(list);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = tmp;
|
||||||
|
|
||||||
|
memset (&list[num], 0,
|
||||||
|
((sizeof(char*)) * (S_LIST_ABS +1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
list[num] = tok;
|
||||||
|
num += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
list[num] = NULL;
|
||||||
|
|
||||||
|
TALLOC_FREE(s);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char **str_list_make_v3_const(TALLOC_CTX *mem_ctx,
|
||||||
|
const char *string,
|
||||||
|
const char *sep)
|
||||||
|
{
|
||||||
|
return const_str_list(str_list_make_v3(mem_ctx, string, sep));
|
||||||
|
}
|
@ -99,7 +99,8 @@ if not bld.env.SAMBA_UTIL_CORE_ONLY:
|
|||||||
rbtree.c rfc1738.c become_daemon.c system.c select.c getpass.c
|
rbtree.c rfc1738.c become_daemon.c system.c select.c getpass.c
|
||||||
genrand_util.c fsusage.c
|
genrand_util.c fsusage.c
|
||||||
params.c util_id.c util_net.c
|
params.c util_id.c util_net.c
|
||||||
util_strlist.c util_paths.c idtree_random.c base64.c
|
util_strlist.c util_strlist_v3.c util_paths.c
|
||||||
|
idtree_random.c base64.c
|
||||||
util_str.c util_str_common.c ms_fnmatch.c
|
util_str.c util_str_common.c ms_fnmatch.c
|
||||||
server_id.c dprintf.c bitmap.c pidfile.c
|
server_id.c dprintf.c bitmap.c pidfile.c
|
||||||
tevent_debug.c memcache.c''',
|
tevent_debug.c memcache.c''',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user