diff options
Diffstat (limited to 'source3')
-rw-r--r-- | source3/Makefile.in | 2 | ||||
-rw-r--r-- | source3/include/proto.h | 2 | ||||
-rw-r--r-- | source3/lib/string_init.c | 77 | ||||
-rw-r--r-- | source3/param/loadparm.c | 52 | ||||
-rwxr-xr-x | source3/wscript_build | 2 |
5 files changed, 54 insertions, 81 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index ff0f1f4f40..e42c1b5684 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -466,7 +466,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \ ../libds/common/flag_mapping.o \ lib/access.o lib/smbrun.o \ ../lib/util/bitmap.o ../lib/util/dprintf.o $(UTIL_REG_OBJ) \ - lib/wins_srv.o lib/string_init.o \ + lib/wins_srv.o \ lib/util_str.o ../lib/util/util_str_common.o \ ../lib/util/util_str.o \ ../lib/util/base64.o lib/util_sid.o \ diff --git a/source3/include/proto.h b/source3/include/proto.h index 101d62d3a3..ebb76effac 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -671,8 +671,6 @@ bool strhasupper(const char *s); bool strhaslower(const char *s); char *StrnCpy(char *dest,const char *src,size_t n); bool in_list(const char *s, const char *list, bool casesensitive); -void string_free(char **s); -bool string_set(char **dest,const char *src); void fstring_sub(char *s,const char *pattern,const char *insert); char *realloc_string_sub2(char *string, const char *pattern, diff --git a/source3/lib/string_init.c b/source3/lib/string_init.c deleted file mode 100644 index 40a6ef059b..0000000000 --- a/source3/lib/string_init.c +++ /dev/null @@ -1,77 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Samba utility functions - - Copyright (C) Andrew Tridgell 1992-2001 - Copyright (C) Simo Sorce 2001-2002 - Copyright (C) Martin Pool 2003 - Copyright (C) James Peach 2006 - Copyright (C) Jeremy Allison 1992-2007 - - 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" - -/* this is used to prevent lots of mallocs of size 1 */ -static const char null_string[] = ""; - -/** - Set a string value, allocing the space for the string -**/ - -static bool string_init(char **dest,const char *src) -{ - size_t l; - - if (!src) - src = ""; - - l = strlen(src); - - if (l == 0) { - *dest = discard_const_p(char, null_string); - } else { - (*dest) = SMB_STRDUP(src); - if ((*dest) == NULL) { - DEBUG(0,("Out of memory in string_init\n")); - return false; - } - } - return(true); -} - -/** - Free a string value. -**/ - -void string_free(char **s) -{ - if (!s || !(*s)) - return; - if (*s == null_string) - *s = NULL; - SAFE_FREE(*s); -} - -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ - -bool string_set(char **dest,const char *src) -{ - string_free(dest); - return(string_init(dest,src)); -} diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index a4d5bfc551..9c49eb094b 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -326,6 +326,58 @@ static void free_param_opts(struct parmlist_entry **popts); #include "lib/param/param_table.c" +/* this is used to prevent lots of mallocs of size 1 */ +static const char null_string[] = ""; + +/** + Set a string value, allocing the space for the string +**/ + +static bool string_init(char **dest,const char *src) +{ + size_t l; + + if (!src) + src = ""; + + l = strlen(src); + + if (l == 0) { + *dest = discard_const_p(char, null_string); + } else { + (*dest) = SMB_STRDUP(src); + if ((*dest) == NULL) { + DEBUG(0,("Out of memory in string_init\n")); + return false; + } + } + return(true); +} + +/** + Free a string value. +**/ + +static void string_free(char **s) +{ + if (!s || !(*s)) + return; + if (*s == null_string) + *s = NULL; + SAFE_FREE(*s); +} + +/** + Set a string value, deallocating any existing space, and allocing the space + for the string +**/ + +static bool string_set(char **dest,const char *src) +{ + string_free(dest); + return(string_init(dest,src)); +} + /*************************************************************************** Initialise the sDefault parameter structure for the printer values. ***************************************************************************/ diff --git a/source3/wscript_build b/source3/wscript_build index 40afdd759a..9125667029 100755 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -1058,7 +1058,7 @@ bld.SAMBA3_SUBSYSTEM('tdb-wrap3', vars=locals()) bld.SAMBA3_LIBRARY('samba3-util', - source='''lib/util_sec.c lib/util_str.c lib/adt_tree.c lib/util_malloc.c lib/memcache.c lib/string_init.c lib/namearray.c lib/file_id.c''', + source='''lib/util_sec.c lib/util_str.c lib/adt_tree.c lib/util_malloc.c lib/memcache.c lib/namearray.c lib/file_id.c''', deps='samba-util charset', private_library=True) |