mescc: Add atoi.

* libc/mlibc.c (atoi): New function.
* module/mes/libc.mes (atoi): New function.
  (libc): Add it.
This commit is contained in:
Jan Nieuwenhuizen 2017-04-17 23:29:54 +02:00
parent 996c449a81
commit 707c3a31cd
2 changed files with 46 additions and 0 deletions

View File

@ -312,6 +312,25 @@ isdigit (int c)
{
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
char itoa_buf[10];

View File

@ -285,6 +285,32 @@ isdigit (char c)
parse-c99)))
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
(let* ((ast (with-input-from-string
"
@ -374,6 +400,7 @@ getenv (char const* s)
strcmp
itoa
isdigit
atoi
malloc
realloc
strncmp