mescc: Add atoi.
* libc/mlibc.c (atoi): New function. * module/mes/libc.mes (atoi): New function. (libc): Add it.
This commit is contained in:
parent
996c449a81
commit
707c3a31cd
19
libc/mlibc.c
19
libc/mlibc.c
|
@ -312,6 +312,25 @@ isdigit (int c)
|
||||||
{
|
{
|
||||||
return (c>='0') && (c<='9');
|
return (c>='0') && (c<='9');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
atoi (char const *s)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int sign = 1;
|
||||||
|
if (*s && *s == '-')
|
||||||
|
{
|
||||||
|
sign = -1;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
while (isdigit (*s))
|
||||||
|
{
|
||||||
|
i *= 10;
|
||||||
|
i += (*s - '0');
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
return i * sign;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char itoa_buf[10];
|
char itoa_buf[10];
|
||||||
|
|
|
@ -285,6 +285,32 @@ isdigit (char c)
|
||||||
parse-c99)))
|
parse-c99)))
|
||||||
ast))
|
ast))
|
||||||
|
|
||||||
|
(define atoi
|
||||||
|
(let* ((ast (with-input-from-string
|
||||||
|
"
|
||||||
|
int
|
||||||
|
atoi (char const *s)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
int sign = 1;
|
||||||
|
if (*s && *s == '-')
|
||||||
|
{
|
||||||
|
sign = -1;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
while (isdigit (*s))
|
||||||
|
{
|
||||||
|
i *= 10;
|
||||||
|
i += (*s - '0');
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
return i * sign;
|
||||||
|
}
|
||||||
|
"
|
||||||
|
;;paredit:"
|
||||||
|
parse-c99)))
|
||||||
|
ast))
|
||||||
|
|
||||||
(define malloc
|
(define malloc
|
||||||
(let* ((ast (with-input-from-string
|
(let* ((ast (with-input-from-string
|
||||||
"
|
"
|
||||||
|
@ -374,6 +400,7 @@ getenv (char const* s)
|
||||||
strcmp
|
strcmp
|
||||||
itoa
|
itoa
|
||||||
isdigit
|
isdigit
|
||||||
|
atoi
|
||||||
malloc
|
malloc
|
||||||
realloc
|
realloc
|
||||||
strncmp
|
strncmp
|
||||||
|
|
Loading…
Reference in New Issue