diff --git a/libc/mlibc.c b/libc/mlibc.c index 8688d7fd..98bcd9dd 100644 --- a/libc/mlibc.c +++ b/libc/mlibc.c @@ -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]; diff --git a/module/mes/libc.mes b/module/mes/libc.mes index 993699fa..31607f8e 100644 --- a/module/mes/libc.mes +++ b/module/mes/libc.mes @@ -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