lib/util Move simple string routines into common code.
authorAndrew Bartlett <abartlet@samba.org>
Fri, 8 Apr 2011 02:02:40 +0000 (12:02 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 13 Apr 2011 04:47:07 +0000 (14:47 +1000)
Signed-off-by: Andrew Tridgell <tridge@samba.org>
lib/util/util_str.c
lib/util/util_str_common.c [new file with mode: 0644]
lib/util/util_strlist.c
lib/util/wscript_build
source3/Makefile.in
source3/lib/util_str.c

index 41183ff57048b79fe15140b5f42fb7c909fb8d8b..f31a8c5598682d647e0456ed2f20fc4df2319042 100644 (file)
@@ -147,30 +147,6 @@ _PUBLIC_ const char *str_format_nbt_domain(TALLOC_CTX *mem_ctx, const char *s)
        return ret;
 }
 
-/**
- * Add a string to an array of strings.
- *
- * num should be a pointer to an integer that holds the current 
- * number of elements in strings. It will be updated by this function.
- */
-_PUBLIC_ bool add_string_to_array(TALLOC_CTX *mem_ctx,
-                        const char *str, const char ***strings, int *num)
-{
-       char *dup_str = talloc_strdup(mem_ctx, str);
-
-       *strings = talloc_realloc(mem_ctx,
-                                   *strings,
-                                   const char *, ((*num)+1));
-
-       if ((*strings == NULL) || (dup_str == NULL))
-               return false;
-
-       (*strings)[*num] = dup_str;
-       *num += 1;
-
-       return true;
-}
-
 /**
  * Parse a string containing a boolean value.
  *
@@ -258,36 +234,6 @@ _PUBLIC_ bool conv_str_u64(const char * str, uint64_t * val)
        return true;
 }
 
-/**
-Do a case-insensitive, whitespace-ignoring string compare.
-**/
-_PUBLIC_ int strwicmp(const char *psz1, const char *psz2)
-{
-       /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
-       /* appropriate value. */
-       if (psz1 == psz2)
-               return (0);
-       else if (psz1 == NULL)
-               return (-1);
-       else if (psz2 == NULL)
-               return (1);
-
-       /* sync the strings on first non-whitespace */
-       while (1) {
-               while (isspace((int)*psz1))
-                       psz1++;
-               while (isspace((int)*psz2))
-                       psz2++;
-               if (toupper((unsigned char)*psz1) != toupper((unsigned char)*psz2) 
-                   || *psz1 == '\0'
-                   || *psz2 == '\0')
-                       break;
-               psz1++;
-               psz2++;
-       }
-       return (*psz1 - *psz2);
-}
-
 /**
  * Compare 2 strings.
  *
diff --git a/lib/util/util_str_common.c b/lib/util/util_str_common.c
new file mode 100644 (file)
index 0000000..e003d73
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+   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    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"
+
+/**
+Do a case-insensitive, whitespace-ignoring string compare.
+**/
+_PUBLIC_ int strwicmp(const char *psz1, const char *psz2)
+{
+       /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
+       /* appropriate value. */
+       if (psz1 == psz2)
+               return (0);
+       else if (psz1 == NULL)
+               return (-1);
+       else if (psz2 == NULL)
+               return (1);
+
+       /* sync the strings on first non-whitespace */
+       while (1) {
+               while (isspace((int)*psz1))
+                       psz1++;
+               while (isspace((int)*psz2))
+                       psz2++;
+               if (toupper_ascii((unsigned char)*psz1) != toupper_ascii((unsigned char)*psz2)
+                   || *psz1 == '\0'
+                   || *psz2 == '\0')
+                       break;
+               psz1++;
+               psz2++;
+       }
+       return (*psz1 - *psz2);
+}
index 953862da85fab967cc53bc76bb33f091e886d208..e8d2a74221803d92fdbbd47c461db342e1dde97a 100644 (file)
@@ -446,6 +446,32 @@ _PUBLIC_ const char **str_list_append_const(const char **list1,
        return ret;
 }
 
+/**
+ * Add a string to an array of strings.
+ *
+ * num should be a pointer to an integer that holds the current
+ * number of elements in strings. It will be updated by this function.
+ */
+_PUBLIC_ bool add_string_to_array(TALLOC_CTX *mem_ctx,
+                        const char *str, const char ***strings, int *num)
+{
+       char *dup_str = talloc_strdup(mem_ctx, str);
+
+       *strings = talloc_realloc(mem_ctx,
+                                   *strings,
+                                   const char *, ((*num)+1));
+
+       if ((*strings == NULL) || (dup_str == NULL)) {
+               *num = 0;
+               return false;
+       }
+
+       (*strings)[*num] = dup_str;
+       *num += 1;
+
+       return true;
+}
+
 /**
   add an entry to a string list
   this assumes s will not change
index 901f200de9ef75eff25a7a8e67aff6d75035a373..8e73e0f3e26ef5b6f41bf2468ef3419ab885116e 100755 (executable)
@@ -7,7 +7,8 @@ bld.SAMBA_LIBRARY('samba-util-common',
                   util_file.c time.c rbtree.c rfc1738.c select.c
                   genrand.c fsusage.c blocking.c become_daemon.c
                   signal.c system.c params.c util.c util_id.c util_net.c
-                  util_strlist.c idtree.c debug.c fault.c base64.c''',
+                  util_strlist.c idtree.c debug.c fault.c base64.c
+                  util_str_common.c''',
                   public_deps='talloc pthread LIBCRYPTO',
                   # until we get all the dependencies in this library in common
                   # we need to allow this library to be built with unresolved symbols
index a0503278b99c00da8872bf94fa53a3d17367caac..2c74ff8cf43560944a4c7791c9901de72b6d5598 100644 (file)
@@ -450,7 +450,8 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/access.o lib/smbrun.o \
          lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \
          lib/wins_srv.o \
-         lib/util_str.o ../lib/util/base64.o lib/util_sid.o \
+         lib/util_str.o ../lib/util/util_str_common.o \
+         ../lib/util/base64.o lib/util_sid.o \
          ../lib/util/charset/util_unistr_w.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \
          lib/util.o lib/util_cmdline.o lib/util_names.o \
          lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
index 0f75f45bf12adb99a1249703db578602b76b16b5..a710fcc35b88e32458f5242415431ddc4217b62f 100644 (file)
@@ -208,36 +208,6 @@ bool strnequal(const char *s1,const char *s2,size_t n)
        return(StrnCaseCmp(s1,s2,n)==0);
 }
 
-/**
-Do a case-insensitive, whitespace-ignoring string compare.
-**/
-
-int strwicmp(const char *psz1, const char *psz2)
-{
-       /* if BOTH strings are NULL, return TRUE, if ONE is NULL return */
-       /* appropriate value. */
-       if (psz1 == psz2)
-               return (0);
-       else if (psz1 == NULL)
-               return (-1);
-       else if (psz2 == NULL)
-               return (1);
-
-       /* sync the strings on first non-whitespace */
-       while (1) {
-               while (isspace((int)*psz1))
-                       psz1++;
-               while (isspace((int)*psz2))
-                       psz2++;
-               if (toupper_ascii(*psz1) != toupper_ascii(*psz2) ||
-                               *psz1 == '\0' || *psz2 == '\0')
-                       break;
-               psz1++;
-               psz2++;
-       }
-       return (*psz1 - *psz2);
-}
-
 /**
  Convert a string to "normal" form.
 **/
@@ -1635,25 +1605,6 @@ void string_append(char **left, const char *right)
        safe_strcat(*left, right, new_len-1);
 }
 
-bool add_string_to_array(TALLOC_CTX *mem_ctx,
-                        const char *str, const char ***strings,
-                        int *num)
-{
-       char *dup_str = talloc_strdup(mem_ctx, str);
-
-       *strings = TALLOC_REALLOC_ARRAY(mem_ctx, *strings,
-                       const char *, (*num)+1);
-
-       if ((*strings == NULL) || (dup_str == NULL)) {
-               *num = 0;
-               return false;
-       }
-
-       (*strings)[*num] = dup_str;
-       *num += 1;
-       return true;
-}
-
 /* Append an sprintf'ed string. Double buffer size on demand. Usable without
  * error checking in between. The indiation that something weird happened is
  * string==NULL */