lib/util Use lib/util/util_str.c in common, including strequal()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 3 May 2011 02:59:36 +0000 (12:59 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 3 May 2011 05:37:07 +0000 (07:37 +0200)
strequal() is now implemented in terms of strcasecmp_m() which is
tested in smbtorture and which does not talloc() for ASCII or
non-ASCII comparions, and has an ASCII fast-path.

Andrew Bartlett

lib/util/util_str.c
lib/util/wscript_build
source3/Makefile.in
source3/lib/util_str.c

index 34dd5be56ebca6cf588307c9b7af133a318dc81c..9842f116530920c549e23547827a09289e0eda5c 100644 (file)
@@ -236,6 +236,6 @@ _PUBLIC_ bool strequal(const char *s1, const char *s2)
        if (!s1 || !s2)
                return false;
   
-       return strcasecmp(s1,s2) == 0;
+       return strcasecmp_m(s1,s2) == 0;
 }
 
index 561dcc4379acf4294bf798393996caa3a6b45f5a..1abaf3dcd5be8e798e485bbbd72010ca0bdac431 100755 (executable)
@@ -5,11 +5,11 @@ common_util_sources = '''talloc_stack.c smb_threads.c xfile.c data_blob.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_str_common.c substitute.c'''
+                    util_str.c util_str_common.c substitute.c'''
 
 common_util_headers = 'debug.h'
 common_util_public_deps = 'talloc pthread LIBCRYPTO'
-s4_util_sources = '''dprintf.c ms_fnmatch.c parmlist.c util_str.c'''
+s4_util_sources = '''dprintf.c ms_fnmatch.c parmlist.c'''
 s4_util_deps = 'DYNCONFIG'
 s4_util_public_deps = 'talloc CHARSET execinfo uid_wrapper'
 s4_util_public_headers = 'attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h util.h'
index 5e7b63dae9deff5f763e7366cfe97c7189987082..9b4518089fe864bcf090acbaa91e546bad5bbc1d 100644 (file)
@@ -457,6 +457,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/bitmap.o lib/dprintf.o $(UTIL_REG_OBJ) \
          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 \
          ../lib/util/charset/util_unistr.o \
          ../lib/util/charset/util_unistr_w.o ../lib/util/charset/codepoints.o ../lib/util/charset/util_str.o lib/util_file.o \
index 4d76cc0a9f5e1d36426295390c3d9c8ad89fa568..583eea40d98594b085c5afe3ff8697e9df01af6a 100644 (file)
@@ -178,21 +178,6 @@ int StrnCaseCmp(const char *s, const char *t, size_t len)
        return ret;
 }
 
-/**
- * Compare 2 strings.
- *
- * @note The comparison is case-insensitive.
- **/
-bool strequal(const char *s1, const char *s2)
-{
-       if (s1 == s2)
-               return(true);
-       if (!s1 || !s2)
-               return(false);
-
-       return(StrCaseCmp(s1,s2)==0);
-}
-
 /**
  * Compare 2 strings up to and including the nth char.
  *
@@ -327,77 +312,6 @@ bool trim_char(char *s,char cfront,char cback)
        return ret;
 }
 
-/**
- Safe string copy into a known length string. maxlength does not
- include the terminating zero.
-**/
-
-char *safe_strcpy_fn(char *dest,
-                    const char *src,
-                    size_t maxlength)
-{
-       size_t len;
-
-       if (!dest) {
-               smb_panic("ERROR: NULL dest in safe_strcpy");
-       }
-
-       if (!src) {
-               *dest = 0;
-               return dest;
-       }
-
-       len = strnlen(src, maxlength+1);
-
-       if (len > maxlength) {
-               DEBUG(0,("ERROR: string overflow by "
-                       "%lu (%lu - %lu) in safe_strcpy [%.50s]\n",
-                        (unsigned long)(len-maxlength), (unsigned long)len,
-                        (unsigned long)maxlength, src));
-               len = maxlength;
-       }
-
-       memmove(dest, src, len);
-       dest[len] = 0;
-       return dest;
-}
-
-/**
- Safe string cat into a string. maxlength does not
- include the terminating zero.
-**/
-char *safe_strcat_fn(char *dest,
-                    const char *src,
-                    size_t maxlength)
-{
-       size_t src_len, dest_len;
-
-       if (!dest) {
-               smb_panic("ERROR: NULL dest in safe_strcat");
-       }
-
-       if (!src)
-               return dest;
-
-       src_len = strnlen(src, maxlength + 1);
-       dest_len = strnlen(dest, maxlength + 1);
-
-       if (src_len + dest_len > maxlength) {
-               DEBUG(0,("ERROR: string overflow by %d "
-                       "in safe_strcat [%.50s]\n",
-                        (int)(src_len + dest_len - maxlength), src));
-               if (maxlength > dest_len) {
-                       memcpy(&dest[dest_len], src, maxlength - dest_len);
-               }
-               dest[maxlength] = 0;
-               return NULL;
-       }
-
-       memcpy(&dest[dest_len], src, src_len);
-       dest[dest_len + src_len] = 0;
-       return dest;
-}
-
 /**
  Like strncpy but always null terminates. Make sure there is room!
  The variable n should always be one less than the available size.