Changeset b2656b1265dafffbe4d03f539399dceb639cc014

Show
Ignore:
Timestamp:
01/10/04 13:11:37 (4 years ago)
Author:
Gildas Bazin <gbazin@videolan.org>
git-committer:
Gildas Bazin <gbazin@videolan.org> 1096629097 +0000
git-parent:

[2ba646a5ea654996b0e627d589bd712acebb2bf8]

git-author:
Gildas Bazin <gbazin@videolan.org> 1096629097 +0000
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.ac

    r067ebc3 rb2656b1  
    298298need_libc=false 
    299299 
    300 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) 
     300AC_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) 
    301301 
    302302dnl Check for usual libc functions 
  • include/vlc_common.h

    r28ed0fc rb2656b1  
    781781#endif 
    782782 
     783#ifndef HAVE_STRTOLL 
     784#   define strtoll vlc_strtoll 
     785    VLC_EXPORT( int64_t, vlc_strtoll, ( const char *nptr, char **endptr, int base ) ); 
     786#elif !defined(__PLUGIN__) 
     787#   define vlc_strtoll NULL 
     788#endif 
     789 
    783790#ifndef HAVE_GETENV 
    784791#   define getenv vlc_getenv 
  • src/extras/libc.c

    r7c239ef rb2656b1  
    2424#include <string.h>                                              /* strdup() */ 
    2525#include <stdlib.h> 
     26#include <ctype.h> 
    2627 
    2728#include <vlc/vlc.h> 
     
    251252 
    252253/***************************************************************************** 
     254 * strtoll: convert a string to a 64 bits int. 
     255 *****************************************************************************/ 
     256#if !defined( HAVE_STRTOLL ) 
     257int64_t vlc_strtoll( const char *nptr, char **endptr, int base ) 
     258{ 
     259    int64_t i_value = 0; 
     260    int sign = 1, newbase = base ? base : 10; 
     261 
     262    while( isspace(*nptr) ) nptr++; 
     263 
     264    if( *nptr == '-' ) 
     265    { 
     266        sign = -1; 
     267        nptr++; 
     268    } 
     269 
     270    /* Try to detect base */ 
     271    if( *nptr == '0' ) 
     272    { 
     273        newbase = 8; 
     274        nptr++; 
     275 
     276        if( *nptr == 'x' ) 
     277        { 
     278            newbase = 16; 
     279            nptr++; 
     280        } 
     281    } 
     282 
     283    if( base && newbase != base ) 
     284    { 
     285        if( endptr ) *endptr = (char *)nptr; 
     286        return i_value; 
     287    } 
     288 
     289    switch( newbase ) 
     290    { 
     291        case 10: 
     292            while( *nptr >= '0' && *nptr <= '9' ) 
     293            { 
     294                i_value *= 10; 
     295                i_value += ( *nptr++ - '0' ); 
     296            } 
     297            if( endptr ) *endptr = (char *)nptr; 
     298            break; 
     299 
     300        case 16: 
     301            while( (*nptr >= '0' && *nptr <= '9') || 
     302                   (*nptr >= 'a' && *nptr <= 'f') || 
     303                   (*nptr >= 'A' && *nptr <= 'F') ) 
     304            { 
     305                int i_valc = 0; 
     306                if(*nptr >= '0' && *nptr <= '9') i_valc = *nptr - '0'; 
     307                else if(*nptr >= 'a' && *nptr <= 'f') i_valc = *nptr - 'a' +10; 
     308                else if(*nptr >= 'A' && *nptr <= 'F') i_valc = *nptr - 'A' +10; 
     309                i_value *= 16; 
     310                i_value += i_valc; 
     311                nptr++; 
     312            } 
     313            if( endptr ) *endptr = (char *)nptr; 
     314            break; 
     315 
     316        default: 
     317            i_value = strtol( nptr, endptr, newbase ); 
     318            break; 
     319    } 
     320 
     321    return i_value * sign; 
     322} 
     323#endif 
     324 
     325/***************************************************************************** 
    253326 * atoll: convert a string to a 64 bits int. 
    254327 *****************************************************************************/ 
    255328#if !defined( HAVE_ATOLL ) 
    256 int64_t vlc_atoll( const char *str ) 
    257 
    258     int64_t i_value = 0; 
    259     int sign = 1; 
    260  
    261     if( *str == '-' ) 
    262     { 
    263         sign = -1; 
    264     } 
    265  
    266     while( *str >= '0' && *str <= '9' ) 
    267     { 
    268         i_value = i_value * 10 + ( *str++ - '0' ); 
    269     } 
    270  
    271     return i_value * sign; 
     329int64_t vlc_atoll( const char *nptr ) 
     330
     331    return strtoll( nptr, (char **)NULL, 10 ); 
    272332} 
    273333#endif