]> git.sesse.net Git - vlc/commitdiff
Simplify, fix and inline strcasecmp and strncasecmp
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 24 May 2008 09:40:57 +0000 (12:40 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 24 May 2008 09:40:57 +0000 (12:40 +0300)
include/vlc_common.h
include/vlc_fixups.h
src/extras/libc.c
src/libvlccore.sym

index 99166d4fba383cfd6d82c9950552259f45c23317..87f2e904a242349bafe4cb2e07ffe560966406c2 100644 (file)
@@ -728,8 +728,6 @@ struct dirent;
 VLC_EXPORT( int, vlc_scandir, ( const char *name, struct dirent ***namelist, int (*filter) ( const struct dirent * ), int (*compar) ( const struct dirent **, const struct dirent ** ) ) );
 VLC_EXPORT( int, vlc_alphasort, ( const struct dirent **a, const struct dirent **b ) );
 
-VLC_EXPORT( int, vlc_strcasecmp, ( const char *s1, const char *s2 ) );
-VLC_EXPORT( int, vlc_strncasecmp, ( const char *s1, const char *s2, size_t n ) );
 VLC_EXPORT( char *, vlc_strcasestr, ( const char *s1, const char *s2 ) );
 
 #if defined(WIN32) || defined(UNDER_CE)
index cd7dc8288a236f6c2f2b2fe1e5dc3b4b9eb3bf28..10f5448ca85b1fda205277b2e7ac3d46850c5869 100644 (file)
@@ -117,7 +117,16 @@ static inline getenv (const char *name)
 
 #ifndef HAVE_STRCASECMP
 # ifndef HAVE_STRICMP
-#  define strcasecmp vlc_strcasecmp
+#  include <ctype.h>
+static inline int strcasecmp (const char *s1, const char *s2)
+{
+    for (size_t i = 0;; i++)
+    {
+        int d = tolower (s1[i]) - tolower (s2[i]);
+        if (d) return d;
+    }
+    return 0;
+}
 # else
 #  define strcasecmp stricmp
 # endif
@@ -125,7 +134,16 @@ static inline getenv (const char *name)
 
 #ifndef HAVE_STRNCASECMP
 # ifndef HAVE_STRNICMP
-#  define strncasecmp vlc_strncasecmp
+#  include <ctype.h>
+static inline int strncasecmp (const char *s1, const char *s2, size_t n)
+{
+    for (size_t i = 0; i < n; i++)
+    {
+        int d = tolower (s1[i]) - tolower (s2[i]);
+        if (d) return d;
+    }
+    return 0;
+}
 # else
 #  define strncasecmp strnicmp
 # endif
index 0c100397ba72d5e2b5dca1bc744f1b897106d435..5b8e9b20b3bee947db8319586440be261e6f4e49 100644 (file)
 #   define strcoll strcmp
 #endif
 
-/*****************************************************************************
- * strcasecmp: compare two strings ignoring case
- *****************************************************************************/
-#if !defined( HAVE_STRCASECMP ) && !defined( HAVE_STRICMP )
-int vlc_strcasecmp( const char *s1, const char *s2 )
-{
-    int c1, c2;
-    if( !s1 || !s2 ) return  -1;
-
-    while( *s1 && *s2 )
-    {
-        c1 = tolower(*s1);
-        c2 = tolower(*s2);
-
-        if( c1 != c2 ) return (c1 < c2 ? -1 : 1);
-        s1++; s2++;
-    }
-
-    if( !*s1 && !*s2 ) return 0;
-    else return (*s1 ? 1 : -1);
-}
-#endif
-
-/*****************************************************************************
- * strncasecmp: compare n chars from two strings ignoring case
- *****************************************************************************/
-#if !defined( HAVE_STRNCASECMP ) && !defined( HAVE_STRNICMP )
-int vlc_strncasecmp( const char *s1, const char *s2, size_t n )
-{
-    int c1, c2;
-    if( !s1 || !s2 ) return  -1;
-
-    while( n > 0 && *s1 && *s2 )
-    {
-        c1 = tolower(*s1);
-        c2 = tolower(*s2);
-
-        if( c1 != c2 ) return (c1 < c2 ? -1 : 1);
-        s1++; s2++; n--;
-    }
-
-    if( !n || (!*s1 && !*s2) ) return 0;
-    else return (*s1 ? 1 : -1);
-}
-#endif
-
 /******************************************************************************
  * strcasestr: find a substring (little) in another substring (big)
  * Case sensitive. Return NULL if not found, return big if little == null
index 24392c1dce4e6e7a00922f1eca985025dd2b5670..0f4a1410c41ae0328d54d98b23920b9d30428657 100644 (file)
@@ -438,10 +438,8 @@ vlc_recvmsg
 vlc_scandir
 vlc_sdp_Start
 vlc_sendmsg
-vlc_strcasecmp
 vlc_strcasestr
 vlc_strlcpy
-vlc_strncasecmp
 vlc_strtoll
 vlc_submodule_create
 __vlc_thread_create