From: RĂ©mi Denis-Courmont Date: Sat, 24 May 2008 16:57:58 +0000 (+0300) Subject: Inline and fix some linking errors X-Git-Tag: 0.9.0-test0~753 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=f160db450ae04c034b306510eaca1aeddc2364b3;p=vlc Inline and fix some linking errors Should fix strlcpy() issues on Linux, but Win32 is surely still totally broken by d754b40584b5fd5ffd5f39a2288a14f9f4662f78 --- diff --git a/include/vlc_common.h b/include/vlc_common.h index 169a1a216f..33c9e63bbb 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 55505992ce..42dbfbf51e 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 +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 +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 f2b9019917..a887c2d2cc 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 c9d01abd7c..430adc72a8 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