1 /*****************************************************************************
2 * strtoll.c: C strtoll() replacement
3 *****************************************************************************
4 * Copyright © 1998-2010 VLC authors and VideoLAN
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
28 long long int strtoll( const char *nptr, char **endptr, int base )
30 long long i_value = 0;
31 int sign = 1, newbase = base ? base : 10;
33 nptr += strspn( nptr, "\t " );
40 /* Try to detect base */
53 if( base && newbase != base )
55 if( endptr ) *endptr = (char *)nptr;
62 while( *nptr >= '0' && *nptr <= '9' )
65 i_value += ( *nptr++ - '0' );
67 if( endptr ) *endptr = (char *)nptr;
71 while( (*nptr >= '0' && *nptr <= '9') ||
72 (*nptr >= 'a' && *nptr <= 'f') ||
73 (*nptr >= 'A' && *nptr <= 'F') )
76 if(*nptr >= '0' && *nptr <= '9') i_valc = *nptr - '0';
77 else if(*nptr >= 'a' && *nptr <= 'f') i_valc = *nptr - 'a' +10;
78 else if(*nptr >= 'A' && *nptr <= 'F') i_valc = *nptr - 'A' +10;
83 if( endptr ) *endptr = (char *)nptr;
87 i_value = strtol( nptr, endptr, newbase );
91 return i_value * sign;