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 /* @(#)astoi.c 1.8 03/06/15 Copyright 1985, 1995-2003 J. Schilling */
15 * astoi() converts a string to int
16 * astol() converts a string to long
18 * Leading tabs and spaces are ignored.
19 * Both return pointer to the first char that has not been used.
20 * Caller must check if this means a bad conversion.
22 * leading "+" is ignored
23 * leading "0" makes conversion octal (base 8)
24 * leading "0x" makes conversion hex (base 16)
26 * Copyright (c) 1985, 1995-2003 J. Schilling
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License version 2
31 * as published by the Free Software Foundation.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License along with
39 * this program; see the file COPYING. If not, write to the Free Software
40 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46 #define is_space(c) ((c) == ' ' || (c) == '\t')
47 #define is_digit(c) ((c) >= '0' && (c) <= '9')
49 ((c) >= 'a' && (c) <= 'f') || \
50 ((c) >= 'A' && (c) <= 'F'))
52 #define to_lower(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A'+'a' : (c))
91 register const char *s;
94 return (astolb(s, l, 0));
99 register const char *s;
104 register long ret = 0L;
113 } else if (*s == '-') {
122 if (*s == 'x' || *s == 'X') {
130 for (; (c = *s) != 0; s++) {
134 } else if (is_hex(c)) {
135 digit = to_lower(c) - 'a' + 10;