Inline and fix some linking errors

Should fix strlcpy() issues on Linux, but Win32 is surely still totally
broken by d754b40584
This commit is contained in:
Rémi Denis-Courmont 2008-05-24 19:57:58 +03:00
parent 04e6970605
commit f160db450a
4 changed files with 28 additions and 72 deletions

View File

@ -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 ) );

View File

@ -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

View File

@ -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

View File

@ -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