From d65bded0c2435a62bf0fe33828d6dc5b9a74f936 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 23 Jul 2012 14:51:39 +0930 Subject: [PATCH] source3/loadparm.c: Move string_set/string_free inside. The only user, so make them static inside loadparm.c Signed-off-by: Rusty Russell Signed-off-by: Andrew Bartlett --- source3/Makefile.in | 2 +- source3/include/proto.h | 2 -- source3/lib/string_init.c | 77 ----------------------------------------------- source3/param/loadparm.c | 52 ++++++++++++++++++++++++++++++++ source3/wscript_build | 2 +- 5 files changed, 54 insertions(+), 81 deletions(-) delete mode 100644 source3/lib/string_init.c diff --git a/source3/Makefile.in b/source3/Makefile.in index ff0f1f4f407..e42c1b5684b 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 101d62d3a3e..ebb76efface 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 40a6ef059ba..00000000000 --- 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 . -*/ - -#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 a4d5bfc5518..9c49eb094b4 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 40afdd759a8..91256670295 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) -- 2.11.4.GIT