From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/lib/util/util_strlist.c | 292 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 source4/lib/util/util_strlist.c (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c new file mode 100644 index 0000000000..ec6c58162f --- /dev/null +++ b/source4/lib/util/util_strlist.c @@ -0,0 +1,292 @@ +/* + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +/* + build a null terminated list of strings from a input string and a + separator list. The separator list must contain characters less than + or equal to 0x2f for this to work correctly on multi-byte strings +*/ +const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) +{ + int num_elements = 0; + const char **ret = NULL; + + if (sep == NULL) { + sep = LIST_SEP; + } + + ret = talloc_array(mem_ctx, const char *, 1); + if (ret == NULL) { + return NULL; + } + + while (string && *string) { + size_t len = strcspn(string, sep); + const char **ret2; + + if (len == 0) { + string += strspn(string, sep); + continue; + } + + ret2 = talloc_realloc(mem_ctx, ret, const char *, num_elements+2); + if (ret2 == NULL) { + talloc_free(ret); + return NULL; + } + ret = ret2; + + ret[num_elements] = talloc_strndup(ret, string, len); + if (ret[num_elements] == NULL) { + talloc_free(ret); + return NULL; + } + + num_elements++; + string += len; + } + + ret[num_elements] = NULL; + + return ret; +} + +/* build a null terminated list of strings from an argv-like input string + Entries are seperated by spaces and can be enclosed by quotes. + Does NOT support escaping + */ +const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) +{ + int num_elements = 0; + const char **ret = NULL; + + ret = talloc_array(mem_ctx, const char *, 1); + if (ret == NULL) { + return NULL; + } + + if (sep == NULL) + sep = " \t\n\r"; + + while (string && *string) { + size_t len = strcspn(string, sep); + char *element; + const char **ret2; + + if (len == 0) { + string += strspn(string, sep); + continue; + } + + if (*string == '\"') { + string++; + len = strcspn(string, "\""); + element = talloc_strndup(ret, string, len); + string += len + 1; + } else { + element = talloc_strndup(ret, string, len); + string += len; + } + + if (element == NULL) { + talloc_free(ret); + return NULL; + } + + ret2 = talloc_realloc(mem_ctx, ret, const char *, num_elements+2); + if (ret2 == NULL) { + talloc_free(ret); + return NULL; + } + ret = ret2; + + ret[num_elements] = element; + + num_elements++; + } + + ret[num_elements] = NULL; + + return ret; + +} + +/* join a list back to one string */ +char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) +{ + char *ret = NULL; + int i; + + if (list[0] == NULL) + return talloc_strdup(mem_ctx, ""); + + ret = talloc_strdup(mem_ctx, list[0]); + + for (i = 1; list[i]; i++) { + ret = talloc_asprintf_append(ret, "%c%s", seperator, list[i]); + } + + return ret; +} + +/* join a list back to one (shell-like) string; entries + * seperated by spaces, using quotes where necessary */ +char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) +{ + char *ret = NULL; + int i; + + if (list[0] == NULL) + return talloc_strdup(mem_ctx, ""); + + if (strchr(list[0], ' ') || strlen(list[0]) == 0) + ret = talloc_asprintf(mem_ctx, "\"%s\"", list[0]); + else + ret = talloc_strdup(mem_ctx, list[0]); + + for (i = 1; list[i]; i++) { + if (strchr(list[i], ' ') || strlen(list[i]) == 0) + ret = talloc_asprintf_append(ret, "%c\"%s\"", sep, list[i]); + else + ret = talloc_asprintf_append(ret, "%c%s", sep, list[i]); + } + + return ret; +} + +/* + return the number of elements in a string list +*/ +size_t str_list_length(const char **list) +{ + size_t ret; + for (ret=0;list && list[ret];ret++) /* noop */ ; + return ret; +} + + +/* + copy a string list +*/ +const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) +{ + int i; + const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); + if (ret == NULL) return NULL; + + for (i=0;list && list[i];i++) { + ret[i] = talloc_strdup(ret, list[i]); + if (ret[i] == NULL) { + talloc_free(ret); + return NULL; + } + } + ret[i] = NULL; + return ret; +} + +/* + Return true if all the elements of the list match exactly. + */ +BOOL str_list_equal(const char **list1, const char **list2) +{ + int i; + + if (list1 == NULL || list2 == NULL) { + return (list1 == list2); + } + + for (i=0;list1[i] && list2[i];i++) { + if (strcmp(list1[i], list2[i]) != 0) { + return False; + } + } + if (list1[i] || list2[i]) { + return False; + } + return True; +} + + +/* + add an entry to a string list +*/ +const char **str_list_add(const char **list, const char *s) +{ + size_t len = str_list_length(list); + const char **ret; + + ret = talloc_realloc(NULL, list, const char *, len+2); + if (ret == NULL) return NULL; + + ret[len] = talloc_strdup(ret, s); + if (ret[len] == NULL) return NULL; + + ret[len+1] = NULL; + + return ret; +} + +/* + remove an entry from a string list +*/ +void str_list_remove(const char **list, const char *s) +{ + int i; + + for (i=0;list[i];i++) { + if (strcmp(list[i], s) == 0) break; + } + if (!list[i]) return; + + for (;list[i];i++) { + list[i] = list[i+1]; + } +} + + +/* + return True if a string is in a list +*/ +BOOL str_list_check(const char **list, const char *s) +{ + int i; + + for (i=0;list[i];i++) { + if (strcmp(list[i], s) == 0) return True; + } + return False; +} + +/* + return True if a string is in a list, case insensitively +*/ +BOOL str_list_check_ci(const char **list, const char *s) +{ + int i; + + for (i=0;list[i];i++) { + if (strcasecmp(list[i], s) == 0) return True; + } + return False; +} -- cgit From aa04388943fe5d7d8c873a6ee8a4cc9af2491532 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 28 Feb 2006 13:12:39 +0000 Subject: r13752: Add doxyfile and fix formatting of comments. Current output is available at http://samba.org/~jelmer/util-api/ (This used to be commit 90812203df151a5e62394306827c72adfe13c63c) --- source4/lib/util/util_strlist.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index ec6c58162f..e3d5126029 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -21,7 +21,12 @@ #include "includes.h" -/* +/** + * @file + * @brief String list manipulation + */ + +/** build a null terminated list of strings from a input string and a separator list. The separator list must contain characters less than or equal to 0x2f for this to work correctly on multi-byte strings @@ -71,9 +76,10 @@ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char * return ret; } -/* build a null terminated list of strings from an argv-like input string - Entries are seperated by spaces and can be enclosed by quotes. - Does NOT support escaping +/** + * build a null terminated list of strings from an argv-like input string + * Entries are seperated by spaces and can be enclosed by quotes. + * Does NOT support escaping */ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { @@ -131,7 +137,9 @@ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const } -/* join a list back to one string */ +/** + * join a list back to one string + */ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) { char *ret = NULL; @@ -149,7 +157,7 @@ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) return ret; } -/* join a list back to one (shell-like) string; entries +/** join a list back to one (shell-like) string; entries * seperated by spaces, using quotes where necessary */ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) { @@ -174,7 +182,7 @@ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) return ret; } -/* +/** return the number of elements in a string list */ size_t str_list_length(const char **list) @@ -185,7 +193,7 @@ size_t str_list_length(const char **list) } -/* +/** copy a string list */ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) @@ -205,7 +213,7 @@ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) return ret; } -/* +/** Return true if all the elements of the list match exactly. */ BOOL str_list_equal(const char **list1, const char **list2) @@ -228,7 +236,7 @@ BOOL str_list_equal(const char **list1, const char **list2) } -/* +/** add an entry to a string list */ const char **str_list_add(const char **list, const char *s) @@ -247,7 +255,7 @@ const char **str_list_add(const char **list, const char *s) return ret; } -/* +/** remove an entry from a string list */ void str_list_remove(const char **list, const char *s) @@ -265,7 +273,7 @@ void str_list_remove(const char **list, const char *s) } -/* +/** return True if a string is in a list */ BOOL str_list_check(const char **list, const char *s) @@ -278,7 +286,7 @@ BOOL str_list_check(const char **list, const char *s) return False; } -/* +/** return True if a string is in a list, case insensitively */ BOOL str_list_check_ci(const char **list, const char *s) -- cgit From af30a32b6924b0f2b701186e435defbca2ebd1aa Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 5 Mar 2006 17:15:19 +0000 Subject: r13840: Mark some functions as public. (This used to be commit 9a188eb1f48a50d92a67a4fc2b3899b90074059a) --- source4/lib/util/util_strlist.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index e3d5126029..48ddbde9e1 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -31,7 +31,7 @@ separator list. The separator list must contain characters less than or equal to 0x2f for this to work correctly on multi-byte strings */ -const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) +_PUBLIC_ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { int num_elements = 0; const char **ret = NULL; @@ -81,7 +81,7 @@ const char **str_list_make(TALLOC_CTX *mem_ctx, const char *string, const char * * Entries are seperated by spaces and can be enclosed by quotes. * Does NOT support escaping */ -const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) +_PUBLIC_ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const char *sep) { int num_elements = 0; const char **ret = NULL; @@ -140,7 +140,7 @@ const char **str_list_make_shell(TALLOC_CTX *mem_ctx, const char *string, const /** * join a list back to one string */ -char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) +_PUBLIC_ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) { char *ret = NULL; int i; @@ -159,7 +159,7 @@ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator) /** join a list back to one (shell-like) string; entries * seperated by spaces, using quotes where necessary */ -char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) +_PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) { char *ret = NULL; int i; @@ -185,7 +185,7 @@ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep) /** return the number of elements in a string list */ -size_t str_list_length(const char **list) +_PUBLIC_ size_t str_list_length(const char **list) { size_t ret; for (ret=0;list && list[ret];ret++) /* noop */ ; @@ -196,7 +196,7 @@ size_t str_list_length(const char **list) /** copy a string list */ -const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) +_PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) { int i; const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); @@ -216,7 +216,7 @@ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) /** Return true if all the elements of the list match exactly. */ -BOOL str_list_equal(const char **list1, const char **list2) +_PUBLIC_ BOOL str_list_equal(const char **list1, const char **list2) { int i; @@ -239,7 +239,7 @@ BOOL str_list_equal(const char **list1, const char **list2) /** add an entry to a string list */ -const char **str_list_add(const char **list, const char *s) +_PUBLIC_ const char **str_list_add(const char **list, const char *s) { size_t len = str_list_length(list); const char **ret; @@ -258,7 +258,7 @@ const char **str_list_add(const char **list, const char *s) /** remove an entry from a string list */ -void str_list_remove(const char **list, const char *s) +_PUBLIC_ void str_list_remove(const char **list, const char *s) { int i; @@ -276,7 +276,7 @@ void str_list_remove(const char **list, const char *s) /** return True if a string is in a list */ -BOOL str_list_check(const char **list, const char *s) +_PUBLIC_ BOOL str_list_check(const char **list, const char *s) { int i; @@ -289,7 +289,7 @@ BOOL str_list_check(const char **list, const char *s) /** return True if a string is in a list, case insensitively */ -BOOL str_list_check_ci(const char **list, const char *s) +_PUBLIC_ BOOL str_list_check_ci(const char **list, const char *s) { int i; -- cgit From 3c5618fb1b5cf484c528a7c957a5a9f260d75a4a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Apr 2007 14:21:56 +0000 Subject: r22373: move in_list() to util_strlist.c to remove the dependency from util.o to next_token() and strcasecmp_m() with this the pidl tests link better on some hosts metze (This used to be commit 54bfc1dccc40883d602402865eff3cfae676e9af) --- source4/lib/util/util_strlist.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 48ddbde9e1..0e9fcd9db9 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -20,6 +20,8 @@ */ #include "includes.h" +#include "pstring.h" +#include "system/locale.h" /** * @file @@ -298,3 +300,26 @@ _PUBLIC_ BOOL str_list_check_ci(const char **list, const char *s) } return False; } + +/** + Check if a string is part of a list. +**/ +_PUBLIC_ BOOL in_list(const char *s, const char *list, BOOL casesensitive) +{ + pstring tok; + const char *p=list; + + if (!list) + return(False); + + while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { + if (casesensitive) { + if (strcmp(tok,s) == 0) + return(True); + } else { + if (strcasecmp_m(tok,s) == 0) + return(True); + } + } + return(False); +} -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/util/util_strlist.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 0e9fcd9db9..cd0e1cdac0 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -6,7 +6,7 @@ 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 2 of the License, or + 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, @@ -15,8 +15,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 4fb038b0b8e7a4bb69ac0d9022684eeaca8a491a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 17:21:16 +0000 Subject: r24710: Use standard boolean type for easier use by external users. (This used to be commit 99f4124137d4a61216e8189f26d4da32882c0f4a) --- source4/lib/util/util_strlist.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index cd0e1cdac0..ab73fb2d15 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -217,7 +217,7 @@ _PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) /** Return true if all the elements of the list match exactly. */ -_PUBLIC_ BOOL str_list_equal(const char **list1, const char **list2) +_PUBLIC_ bool str_list_equal(const char **list1, const char **list2) { int i; @@ -227,13 +227,13 @@ _PUBLIC_ BOOL str_list_equal(const char **list1, const char **list2) for (i=0;list1[i] && list2[i];i++) { if (strcmp(list1[i], list2[i]) != 0) { - return False; + return false; } } if (list1[i] || list2[i]) { - return False; + return false; } - return True; + return true; } @@ -275,50 +275,50 @@ _PUBLIC_ void str_list_remove(const char **list, const char *s) /** - return True if a string is in a list + return true if a string is in a list */ -_PUBLIC_ BOOL str_list_check(const char **list, const char *s) +_PUBLIC_ bool str_list_check(const char **list, const char *s) { int i; for (i=0;list[i];i++) { - if (strcmp(list[i], s) == 0) return True; + if (strcmp(list[i], s) == 0) return true; } - return False; + return false; } /** - return True if a string is in a list, case insensitively + return true if a string is in a list, case insensitively */ -_PUBLIC_ BOOL str_list_check_ci(const char **list, const char *s) +_PUBLIC_ bool str_list_check_ci(const char **list, const char *s) { int i; for (i=0;list[i];i++) { - if (strcasecmp(list[i], s) == 0) return True; + if (strcasecmp(list[i], s) == 0) return true; } - return False; + return false; } /** Check if a string is part of a list. **/ -_PUBLIC_ BOOL in_list(const char *s, const char *list, BOOL casesensitive) +_PUBLIC_ bool in_list(const char *s, const char *list, bool casesensitive) { pstring tok; const char *p=list; if (!list) - return(False); + return false; while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { if (casesensitive) { if (strcmp(tok,s) == 0) - return(True); + return true; } else { if (strcasecmp_m(tok,s) == 0) - return(True); + return true; } } - return(False); + return false; } -- cgit From b50ef4caef44e3b45445728818f3bca09273249d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 16:54:39 +0000 Subject: r25007: Remove more uses of pstring, move ntlmauth-specific utility function to ntlm-auth.c (This used to be commit 6f224480b230ab7ccfc0417c13e7f4fc3f6f2a13) --- source4/lib/util/util_strlist.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index ab73fb2d15..a8b106a567 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -300,25 +300,4 @@ _PUBLIC_ bool str_list_check_ci(const char **list, const char *s) return false; } -/** - Check if a string is part of a list. -**/ -_PUBLIC_ bool in_list(const char *s, const char *list, bool casesensitive) -{ - pstring tok; - const char *p=list; - if (!list) - return false; - - while (next_token(&p,tok,LIST_SEP,sizeof(tok))) { - if (casesensitive) { - if (strcmp(tok,s) == 0) - return true; - } else { - if (strcasecmp_m(tok,s) == 0) - return true; - } - } - return false; -} -- cgit From 3b6186a67630cf05bc33e6e9288e132f39173ef4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 17:59:53 +0000 Subject: r25008: Remove use of pstring. (This used to be commit c57869e2620de30c303b0cb2f70cd07b32f269fc) --- source4/lib/util/util_strlist.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index a8b106a567..ed4ab00031 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "pstring.h" #include "system/locale.h" /** -- cgit From 9a012df08ee829c1d40fc88ba12a0ea479f60be0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 23:21:00 +0000 Subject: r25175: Change to talloc_asprintf_append_buffer(). Jeremy. (This used to be commit 0844dbf597191b3e4d35a696695b229e986daec4) --- source4/lib/util/util_strlist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index ed4ab00031..1f1cc17d00 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -151,7 +151,7 @@ _PUBLIC_ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char sepera ret = talloc_strdup(mem_ctx, list[0]); for (i = 1; list[i]; i++) { - ret = talloc_asprintf_append(ret, "%c%s", seperator, list[i]); + ret = talloc_asprintf_append_buffer(ret, "%c%s", seperator, list[i]); } return ret; @@ -174,9 +174,9 @@ _PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char for (i = 1; list[i]; i++) { if (strchr(list[i], ' ') || strlen(list[i]) == 0) - ret = talloc_asprintf_append(ret, "%c\"%s\"", sep, list[i]); + ret = talloc_asprintf_append_buffer(ret, "%c\"%s\"", sep, list[i]); else - ret = talloc_asprintf_append(ret, "%c%s", sep, list[i]); + ret = talloc_asprintf_append_buffer(ret, "%c%s", sep, list[i]); } return ret; -- cgit From 80b62dae14ce067fa9f13145d4ad8a8fef8b17a3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 12 Dec 2007 14:09:15 +0100 Subject: r26417: Make str_list_copy(mem_ctx, NULL) return NULL rather than an empty list. (This used to be commit cf8636c8b77c745812376d0ea6f0fb6246a2e4fb) --- source4/lib/util/util_strlist.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/lib/util/util_strlist.c') diff --git a/source4/lib/util/util_strlist.c b/source4/lib/util/util_strlist.c index 1f1cc17d00..30de4b962d 100644 --- a/source4/lib/util/util_strlist.c +++ b/source4/lib/util/util_strlist.c @@ -199,8 +199,14 @@ _PUBLIC_ size_t str_list_length(const char **list) _PUBLIC_ const char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list) { int i; - const char **ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); - if (ret == NULL) return NULL; + const char **ret; + + if (list == NULL) + return NULL; + + ret = talloc_array(mem_ctx, const char *, str_list_length(list)+1); + if (ret == NULL) + return NULL; for (i=0;list && list[i];i++) { ret[i] = talloc_strdup(ret, list[i]); -- cgit