summaryrefslogtreecommitdiff
path: root/sys/src/libc/port/atol.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-08-03 18:10:53 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-08-03 18:10:53 +0200
commitd457a43461852636db313c4854590b2c62a21e23 (patch)
tree14df482e9e64f59872558aa6e7ce7bd076112fae /sys/src/libc/port/atol.c
parent25139465363b2230b69789013e3e0b5f82d76564 (diff)
libc: make atoi() not parse c-style octal and hex numbers
interpreting octal breaks parsing of decimal numbers with leading zeros. the manpage listed this in the BUGS section, so we'r going to fix it as this just causes confusion as most callers of atoi() do not expect it.
Diffstat (limited to 'sys/src/libc/port/atol.c')
-rw-r--r--sys/src/libc/port/atol.c43
1 files changed, 2 insertions, 41 deletions
diff --git a/sys/src/libc/port/atol.c b/sys/src/libc/port/atol.c
index 6928da7bd..cf7270c6f 100644
--- a/sys/src/libc/port/atol.c
+++ b/sys/src/libc/port/atol.c
@@ -4,50 +4,11 @@
long
atol(char *s)
{
- long n;
- int f, c;
-
- n = 0;
- f = 0;
- while(*s == ' ' || *s == '\t')
- s++;
- if(*s == '-' || *s == '+') {
- if(*s++ == '-')
- f = 1;
- while(*s == ' ' || *s == '\t')
- s++;
- }
- if(s[0]=='0' && s[1]) {
- if(s[1]=='x' || s[1]=='X'){
- s += 2;
- for(;;) {
- c = *s;
- if(c >= '0' && c <= '9')
- n = n*16 + c - '0';
- else
- if(c >= 'a' && c <= 'f')
- n = n*16 + c - 'a' + 10;
- else
- if(c >= 'A' && c <= 'F')
- n = n*16 + c - 'A' + 10;
- else
- break;
- s++;
- }
- } else
- while(*s >= '0' && *s <= '7')
- n = n*8 + *s++ - '0';
- } else
- while(*s >= '0' && *s <= '9')
- n = n*10 + *s++ - '0';
- if(f)
- n = -n;
- return n;
+ return strtol(s, nil, 10);
}
int
atoi(char *s)
{
-
- return atol(s);
+ return strtol(s, nil, 10);
}