Commit f160db45 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Inline and fix some linking errors

Should fix strlcpy() issues on Linux, but Win32 is surely still totally
broken by d754b405
parent 04e69706
...@@ -719,8 +719,6 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw ) ...@@ -719,8 +719,6 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
#define VLC_UNUSED(x) (void)(x) #define VLC_UNUSED(x) (void)(x)
/* Stuff defined in src/extras/libc.c */ /* 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( size_t, vlc_strlcpy, ( char *, const char *, size_t ) );
VLC_EXPORT( long long, vlc_strtoll, ( const char *nptr, char **endptr, int base ) ); VLC_EXPORT( long long, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
......
...@@ -40,11 +40,29 @@ static inline char *strdup (const char *str) ...@@ -40,11 +40,29 @@ static inline char *strdup (const char *str)
#endif #endif
#ifndef HAVE_VASPRINTF #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 #endif
#ifndef HAVE_ASPRINTF #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 #endif
#ifndef HAVE_STRNLEN #ifndef HAVE_STRNLEN
......
...@@ -74,9 +74,11 @@ ...@@ -74,9 +74,11 @@
* strcasestr: find a substring (little) in another substring (big) * strcasestr: find a substring (little) in another substring (big)
* Case sensitive. Return NULL if not found, return big if little == null * 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 ) 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; char *p_pos = (char *)psz_big;
if( !psz_big || !psz_little || !*psz_little ) return p_pos; 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 ) ...@@ -98,71 +100,8 @@ char * vlc_strcasestr( const char *psz_big, const char *psz_little )
p_pos++; p_pos++;
} }
return NULL; 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 #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. * strtoll: convert a string to a 64 bits int.
...@@ -249,9 +188,11 @@ long long vlc_strtoll( const char *nptr, char **endptr, int base ) ...@@ -249,9 +188,11 @@ long long vlc_strtoll( const char *nptr, char **endptr, int base )
* *
* @return strlen(src) * @return strlen(src)
*/ */
#ifndef HAVE_STRLCPY
extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize) 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; size_t length;
for (length = 1; (length < bufsize) && *src; 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) ...@@ -264,8 +205,8 @@ extern size_t vlc_strlcpy (char *tgt, const char *src, size_t bufsize)
length++; length++;
return length - 1; return length - 1;
}
#endif #endif
}
/***************************************************************************** /*****************************************************************************
* vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters
......
...@@ -367,7 +367,6 @@ __var_Get ...@@ -367,7 +367,6 @@ __var_Get
__var_Set __var_Set
__var_TriggerCallback __var_TriggerCallback
__var_Type __var_Type
vlc_asprintf
vlc_b64_decode vlc_b64_decode
vlc_b64_decode_binary vlc_b64_decode_binary
vlc_b64_decode_binary_to_buffer vlc_b64_decode_binary_to_buffer
...@@ -431,6 +430,7 @@ __vlc_object_yield ...@@ -431,6 +430,7 @@ __vlc_object_yield
vlc_pthread_fatal vlc_pthread_fatal
vlc_rand_bytes vlc_rand_bytes
vlc_sdp_Start vlc_sdp_Start
vlc_strlcpy
vlc_strtoll vlc_strtoll
vlc_submodule_create vlc_submodule_create
__vlc_thread_create __vlc_thread_create
...@@ -440,7 +440,6 @@ __vlc_thread_set_priority ...@@ -440,7 +440,6 @@ __vlc_thread_set_priority
vlc_threadvar_create vlc_threadvar_create
vlc_threadvar_delete vlc_threadvar_delete
vlc_ureduce vlc_ureduce
vlc_vasprintf
VLC_Version VLC_Version
vlc_wraptext vlc_wraptext
vlm_Control vlm_Control
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment