Commit b2656b12 authored by Gildas Bazin's avatar Gildas Bazin

* src/extras/libc.c: strtoll() replacement when not available.

parent 2ba646a5
...@@ -297,7 +297,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd ...@@ -297,7 +297,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd
dnl Check for system libs needed dnl Check for system libs needed
need_libc=false need_libc=false
AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol strtof isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign gethostbyname2 if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon) AC_CHECK_FUNCS(gettimeofday select strerror strtod strtol strtof strtoll isatty vasprintf asprintf swab sigrelse getpwuid memalign posix_memalign gethostbyname2 if_nametoindex atoll getenv putenv setenv gmtime_r ctime_r localtime_r lrintf daemon)
dnl Check for usual libc functions dnl Check for usual libc functions
AC_CHECK_FUNCS(strdup strndup atof lseek) AC_CHECK_FUNCS(strdup strndup atof lseek)
......
...@@ -780,6 +780,13 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw ) ...@@ -780,6 +780,13 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
# define vlc_atoll NULL # define vlc_atoll NULL
#endif #endif
#ifndef HAVE_STRTOLL
# define strtoll vlc_strtoll
VLC_EXPORT( int64_t, vlc_strtoll, ( const char *nptr, char **endptr, int base ) );
#elif !defined(__PLUGIN__)
# define vlc_strtoll NULL
#endif
#ifndef HAVE_GETENV #ifndef HAVE_GETENV
# define getenv vlc_getenv # define getenv vlc_getenv
VLC_EXPORT( char *, vlc_getenv, ( const char *name ) ); VLC_EXPORT( char *, vlc_getenv, ( const char *name ) );
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
*****************************************************************************/ *****************************************************************************/
#include <string.h> /* strdup() */ #include <string.h> /* strdup() */
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include <vlc/vlc.h> #include <vlc/vlc.h>
...@@ -250,28 +251,87 @@ double vlc_atof( const char *nptr ) ...@@ -250,28 +251,87 @@ double vlc_atof( const char *nptr )
#endif #endif
/***************************************************************************** /*****************************************************************************
* atoll: convert a string to a 64 bits int. * strtoll: convert a string to a 64 bits int.
*****************************************************************************/ *****************************************************************************/
#if !defined( HAVE_ATOLL ) #if !defined( HAVE_STRTOLL )
int64_t vlc_atoll( const char *str ) int64_t vlc_strtoll( const char *nptr, char **endptr, int base )
{ {
int64_t i_value = 0; int64_t i_value = 0;
int sign = 1; int sign = 1, newbase = base ? base : 10;
if( *str == '-' ) while( isspace(*nptr) ) nptr++;
if( *nptr == '-' )
{ {
sign = -1; sign = -1;
nptr++;
} }
while( *str >= '0' && *str <= '9' ) /* Try to detect base */
if( *nptr == '0' )
{ {
i_value = i_value * 10 + ( *str++ - '0' ); newbase = 8;
nptr++;
if( *nptr == 'x' )
{
newbase = 16;
nptr++;
}
}
if( base && newbase != base )
{
if( endptr ) *endptr = (char *)nptr;
return i_value;
}
switch( newbase )
{
case 10:
while( *nptr >= '0' && *nptr <= '9' )
{
i_value *= 10;
i_value += ( *nptr++ - '0' );
}
if( endptr ) *endptr = (char *)nptr;
break;
case 16:
while( (*nptr >= '0' && *nptr <= '9') ||
(*nptr >= 'a' && *nptr <= 'f') ||
(*nptr >= 'A' && *nptr <= 'F') )
{
int i_valc = 0;
if(*nptr >= '0' && *nptr <= '9') i_valc = *nptr - '0';
else if(*nptr >= 'a' && *nptr <= 'f') i_valc = *nptr - 'a' +10;
else if(*nptr >= 'A' && *nptr <= 'F') i_valc = *nptr - 'A' +10;
i_value *= 16;
i_value += i_valc;
nptr++;
}
if( endptr ) *endptr = (char *)nptr;
break;
default:
i_value = strtol( nptr, endptr, newbase );
break;
} }
return i_value * sign; return i_value * sign;
} }
#endif #endif
/*****************************************************************************
* atoll: convert a string to a 64 bits int.
*****************************************************************************/
#if !defined( HAVE_ATOLL )
int64_t vlc_atoll( const char *nptr )
{
return strtoll( nptr, (char **)NULL, 10 );
}
#endif
/***************************************************************************** /*****************************************************************************
* lseek: reposition read/write file offset. * lseek: reposition read/write file offset.
***************************************************************************** *****************************************************************************
......
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