Initial revision
This commit is contained in:
53
lang/cem/libcc.ansi/stdlib/strtol.c
Normal file
53
lang/cem/libcc.ansi/stdlib/strtol.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
long int
|
||||
strtol(register const char *p, char **pp, int base)
|
||||
{
|
||||
register long val, v;
|
||||
register int c;
|
||||
int sign = 1;
|
||||
|
||||
if (pp) *pp = p;
|
||||
while (isspace(*p)) p++;
|
||||
c = *p;
|
||||
|
||||
switch (c) {
|
||||
case '-':
|
||||
sign = -1;
|
||||
/* fallthrough */
|
||||
case '+':
|
||||
p++;
|
||||
}
|
||||
|
||||
/* this is bizare */
|
||||
if (base==16 && *p=='0' && (*(p+1)=='x' || *(p+1)=='X'))
|
||||
p += 2;
|
||||
|
||||
while (isdigit(c = *p++) || isalpha(c)) {
|
||||
if (isalpha(c))
|
||||
v = 10 + (isupper(c) ? c - 'A' : c - 'a');
|
||||
else
|
||||
v = c - '0';
|
||||
if (v >= base) {
|
||||
p--;
|
||||
break;
|
||||
}
|
||||
val = (val * base) + v;
|
||||
}
|
||||
if (pp) *pp = p-1;
|
||||
return sign * val;
|
||||
}
|
||||
|
||||
|
||||
unsigned long int
|
||||
strtoul(register const char *p, char **pp, int base)
|
||||
{
|
||||
return (unsigned long)strtol(p, pp, base);
|
||||
}
|
||||
Reference in New Issue
Block a user