[vlc-devel] commit: Inline and fix some linking errors ( Rémi Denis-Courmont )

git version control git at videolan.org
Sat May 24 18:58:30 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Sat May 24 19:57:58 2008 +0300| [f160db450ae04c034b306510eaca1aeddc2364b3]

Inline and fix some linking errors

Should fix strlcpy() issues on Linux, but Win32 is surely still totally
broken by d754b40584b5fd5ffd5f39a2288a14f9f4662f78

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f160db450ae04c034b306510eaca1aeddc2364b3
---

 include/vlc_common.h |    2 -
 include/vlc_fixups.h |   22 +++++++++++++-
 src/extras/libc.c    |   73 +++++---------------------------------------------
 src/libvlccore.sym   |    3 +-
 4 files changed, 28 insertions(+), 72 deletions(-)

diff --git a/include/vlc_common.h b/include/vlc_common.h
index 169a1a2..33c9e63 100644
--- a/include/vlc_common.h
+++ b/include/vlc_common.h
@@ -719,8 +719,6 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
 #define VLC_UNUSED(x) (void)(x)
 
 /* Stuff defined in src/extras/libc.c */
-VLC_EXPORT( int, vlc_vasprintf, (char **, const char *, va_list ) );
-VLC_EXPORT( int, vlc_asprintf, (char **, const char *, ... ) ATTRIBUTE_FORMAT( 2, 3 ) );
 VLC_EXPORT( size_t, vlc_strlcpy, ( char *, const char *, size_t ) );
 VLC_EXPORT( long long, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
 
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 5550599..42dbfbf 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -40,11 +40,29 @@ static inline char *strdup (const char *str)
 #endif
 
 #ifndef HAVE_VASPRINTF
-# define vasprintf vlc_vasprintf
+# include <stdarg.h>
+static inline int vasprintf (char **strp, const char *fmt, va_list ap)
+{
+    int len = vsnprintf (NULL, 0, fmt, ap) + 1;
+    char *res = malloc (len);
+    if (res == NULL)
+        return -1;
+    *strp = res;
+    return vsprintf (res, fmt, ap);
+}
 #endif
 
 #ifndef HAVE_ASPRINTF
-# define asprintf vlc_asprintf
+# include <stdarg.h>
+static inline int asprintf (char **strp, const char *fmt, ...)
+{
+    va_list ap;
+    int ret;
+    va_start (fmt, ap);
+    ret = vasprintf (strp, fmt, ap);
+    va_end (ap);
+    return ret;
+}
 #endif
 
 #ifndef HAVE_STRNLEN
diff --git a/src/extras/libc.c b/src/extras/libc.c
index f2b9019..a887c2d 100644
--- a/src/extras/libc.c
+++ b/src/extras/libc.c
@@ -74,9 +74,11 @@
  * strcasestr: find a substring (little) in another substring (big)
  * Case sensitive. Return NULL if not found, return big if little == null
  *****************************************************************************/
-#if !defined( HAVE_STRCASESTR ) && !defined( HAVE_STRISTR )
 char * vlc_strcasestr( const char *psz_big, const char *psz_little )
 {
+#if defined (HAVE_STRCASESTR) || defined (HAVE_STRISTR)
+    return strcasestr (psz_big, psz_little);
+#else
     char *p_pos = (char *)psz_big;
 
     if( !psz_big || !psz_little || !*psz_little ) return p_pos;
@@ -98,71 +100,8 @@ char * vlc_strcasestr( const char *psz_big, const char *psz_little )
         p_pos++;
     }
     return NULL;
-}
-#endif
-
-/*****************************************************************************
- * vasprintf:
- *****************************************************************************/
-#if !defined(HAVE_VASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
-int vlc_vasprintf(char **strp, const char *fmt, va_list ap)
-{
-    /* Guess we need no more than 100 bytes. */
-    int     i_size = 100;
-    char    *p = malloc( i_size );
-    int     n;
-
-    if( p == NULL )
-    {
-        *strp = NULL;
-        return -1;
-    }
-
-    for( ;; )
-    {
-        /* Try to print in the allocated space. */
-        n = vsnprintf( p, i_size, fmt, ap );
-
-        /* If that worked, return the string. */
-        if (n > -1 && n < i_size)
-        {
-            *strp = p;
-            return strlen( p );
-        }
-        /* Else try again with more space. */
-        if (n > -1)    /* glibc 2.1 */
-        {
-           i_size = n+1; /* precisely what is needed */
-        }
-        else           /* glibc 2.0 */
-        {
-           i_size *= 2;  /* twice the old size */
-        }
-        if( (p = realloc( p, i_size ) ) == NULL)
-        {
-            *strp = NULL;
-            return -1;
-        }
-    }
-}
 #endif
-
-/*****************************************************************************
- * asprintf:
- *****************************************************************************/
-#if !defined(HAVE_ASPRINTF) || defined(__APPLE__) || defined(SYS_BEOS)
-int vlc_asprintf( char **strp, const char *fmt, ... )
-{
-    va_list args;
-    int i_ret;
-
-    va_start( args, fmt );
-    i_ret = vasprintf( strp, fmt, args );
-    va_end( args );
-
-    return i_ret;
 }
-#endif
 
 /*****************************************************************************
  * strtoll: convert a string to a 64 bits int.
@@ -249,9 +188,11 @@ long long vlc_strtoll( const char *nptr, char **endptr, int base )
  *
  * @return strlen(src)
  */
-#ifndef HAVE_STRLCPY
 extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize)
 {
+#ifdef HAVE_STRLCPY
+    return strlcpy (tgt, src, bufsize);
+#else
     size_t length;
 
     for (length = 1; (length < bufsize) && *src; length++)
@@ -264,8 +205,8 @@ extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize)
         length++;
 
     return length - 1;
-}
 #endif
+}
 
 /*****************************************************************************
  * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index c9d01ab..430adc7 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -367,7 +367,6 @@ __var_Get
 __var_Set
 __var_TriggerCallback
 __var_Type
-vlc_asprintf
 vlc_b64_decode
 vlc_b64_decode_binary
 vlc_b64_decode_binary_to_buffer
@@ -431,6 +430,7 @@ __vlc_object_yield
 vlc_pthread_fatal
 vlc_rand_bytes
 vlc_sdp_Start
+vlc_strlcpy
 vlc_strtoll
 vlc_submodule_create
 __vlc_thread_create
@@ -440,7 +440,6 @@ __vlc_thread_set_priority
 vlc_threadvar_create
 vlc_threadvar_delete
 vlc_ureduce
-vlc_vasprintf
 VLC_Version
 vlc_wraptext
 vlm_Control




More information about the vlc-devel mailing list