]> git.sesse.net Git - vlc/commitdiff
* src/extras/libc.c: strtoll() replacement when not available.
authorGildas Bazin <gbazin@videolan.org>
Fri, 1 Oct 2004 11:11:37 +0000 (11:11 +0000)
committerGildas Bazin <gbazin@videolan.org>
Fri, 1 Oct 2004 11:11:37 +0000 (11:11 +0000)
configure.ac
include/vlc_common.h
src/extras/libc.c

index 60c74b62d5e090247aa4e52a83f55f6d88dde52b..50700fc515b7154c7192f91f91fc3d0b834d8361 100644 (file)
@@ -297,7 +297,7 @@ CPPFLAGS_save="${CPPFLAGS_save} -DSYS_`echo ${SYS} | sed -e 's/-.*//' | tr 'abcd
 dnl Check for system libs needed
 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
 AC_CHECK_FUNCS(strdup strndup atof lseek)
index 11d5b8b1f27b66d1ac1b5628e16481e6f7a3e8da..aab26e3760ec0ed277118e5beced4c2a11fdc0ec 100644 (file)
@@ -780,6 +780,13 @@ static inline void _SetQWBE( uint8_t *p, uint64_t i_qw )
 #   define vlc_atoll NULL
 #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
 #   define getenv vlc_getenv
     VLC_EXPORT( char *, vlc_getenv, ( const char *name ) );
index b8621142457cd8c4593c8534c249356c48c5d565..f9b450839389aa02087b34cfd0c7e78d6ec09d77 100644 (file)
@@ -23,6 +23,7 @@
  *****************************************************************************/
 #include <string.h>                                              /* strdup() */
 #include <stdlib.h>
+#include <ctype.h>
 
 #include <vlc/vlc.h>
 
@@ -250,28 +251,87 @@ double vlc_atof( const char *nptr )
 #endif
 
 /*****************************************************************************
- * atoll: convert a string to a 64 bits int.
+ * strtoll: convert a string to a 64 bits int.
  *****************************************************************************/
-#if !defined( HAVE_ATOLL )
-int64_t vlc_atoll( const char *str )
+#if !defined( HAVE_STRTOLL )
+int64_t vlc_strtoll( const char *nptr, char **endptr, int base )
 {
     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;
+        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;
 }
 #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.
  *****************************************************************************