2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)astoll.c 1.3 03/06/15 Copyright 1985, 2000-2003 J. Schilling */
15 * astoll() converts a string to long long
17 * Leading tabs and spaces are ignored.
18 * Both return pointer to the first char that has not been used.
19 * Caller must check if this means a bad conversion.
21 * leading "+" is ignored
22 * leading "0" makes conversion octal (base 8)
23 * leading "0x" makes conversion hex (base 16)
25 * Llong is silently reverted to long if the compiler does not
28 * Copyright (c) 1985, 2000-2003 J. Schilling
31 * This program is free software; you can redistribute it and/or modify
32 * it under the terms of the GNU General Public License version 2
33 * as published by the Free Software Foundation.
35 * This program is distributed in the hope that it will be useful,
36 * but WITHOUT ANY WARRANTY; without even the implied warranty of
37 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38 * GNU General Public License for more details.
40 * You should have received a copy of the GNU General Public License along with
41 * this program; see the file COPYING. If not, write to the Free Software
42 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
50 #define is_space(c) ((c) == ' ' || (c) == '\t')
51 #define is_digit(c) ((c) >= '0' && (c) <= '9')
53 ((c) >= 'a' && (c) <= 'f') || \
54 ((c) >= 'A' && (c) <= 'F'))
56 #define to_lower(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A'+'a' : (c))
60 register const char *s;
63 return (astollb(s, l, 0));
68 register const char *s;
73 register Llong ret = (Llong)0;
82 } else if (*s == '-') {
91 if (*s == 'x' || *s == 'X') {
99 for (; (c = *s) != 0; s++) {
103 } else if (is_hex(c)) {
104 digit = to_lower(c) - 'a' + 10;