mescc: Support gcc-3.2: Implement integer strto*.

* lib/libc+tcc.c (strtoll, strtoul): Call strtoul.
This commit is contained in:
Jan Nieuwenhuizen 2018-06-06 22:39:57 +02:00
parent 04302b3fe4
commit cc466662b9
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
4 changed files with 117 additions and 24 deletions

View file

@ -140,6 +140,7 @@ t
93-fread-fwrite
94-unsetenv
95-signal
96-strto
"
# 90: needs GNU, fails for mescc, passes for tcc

View file

@ -49,13 +49,13 @@ void unsetenv (char const *name);
void *malloc (size_t);
void qsort (void *base, size_t nmemb, size_t size, int (*compar)(void const *, void const *));
void *realloc (void *p, size_t size);
double strtod (char const *nptr, char **endptr);
float strtof (char const *nptr, char **endptr);
long double strtold (char const *nptr, char **endptr);
long strtol (char const *nptr, char **endptr, int base);
long long strtoll (char const *nptr, char **endptr, int base);
unsigned long strtoul (char const *nptr, char **endptr, int base);
unsigned long long strtoull (char const *nptr, char **endptr, int base);
double strtod (char const *string, char **tailptr);
float strtof (char const *string, char **tailptr);
long double strtold (char const *string, char **tailptr);
long strtol (char const *string, char **tailptr, int base);
long long strtoll (char const *string, char **tailptr, int base);
unsigned long strtoul (char const *string, char **tailptr, int base);
unsigned long long strtoull (char const *string, char **tailptr, int base);
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0

View file

@ -218,6 +218,7 @@ fseek (FILE *stream, long offset, int whence)
int
gettimeofday (struct timeval *tv, struct timezone *tz)
{
eputs ("gettimeofday stub\n");
return 0;
}
@ -450,57 +451,91 @@ strstr (char const *haystack, char const *needle)
}
double
strtod (char const *nptr, char **endptr)
strtod (char const *string, char **tailptr)
{
eputs ("strtod stub\n");
}
float
strtof (char const *nptr, char **endptr)
strtof (char const *string, char **tailptr)
{
return strtod (nptr, endptr);
return strtod (string, tailptr);
}
long double
strtold (char const *nptr, char **endptr)
strtold (char const *string, char **tailptr)
{
return strtod (nptr, endptr);
return strtod (string, tailptr);
}
long
strtol (char const *nptr, char **endptr, int base)
strtol (char const *string, char **tailptr, int base)
{
if (!strncmp (nptr, "0x", 2))
if (!strncmp (string, "0x", 2))
{
char const *p = nptr + 2;
return abtoi (&p, 16);
string += 2;
base = 16;
}
return abtoi (&nptr, base);
if (tailptr)
{
*tailptr = string;
return abtoi (tailptr, base);
}
char **p = &string;
return abtoi (p, base);
}
#if 1
long long int
strtoll (char const *nptr, char **endptr, int base)
strtoll (char const *string, char **tailptr, int base)
{
return strtol (string, tailptr, base);
}
unsigned long
strtoul (char const *string, char **tailptr, int base)
{
return strtol (string, tailptr, base);
}
unsigned long long
strtoull (char const *string, char **tailptr, int base)
{
return strtol (string, tailptr, base);
}
#else
long long int
strtoll (char const *string, char **tailptr, int base)
{
eputs ("strtoll stub\n");
return 0;
}
unsigned long
strtoul (char const *nptr, char **endptr, int base)
strtoul (char const *string, char **tailptr, int base)
{
eputs ("strtoul stub\n");
return 0;
}
unsigned long long
strtoull (char const *p, char **endptr, int base)
strtoull (char const *string, char **tailptr, int base)
{
*endptr = p;
return abtoi (endptr, base);
// *endptr = p;
// return abtoi (endptr, base);
eputs ("strtoull stub\n");
return 0;
}
time_t time (time_t *tloc)
#endif
time_t
time (time_t *tloc)
{
eputs ("time stub\n");
return 0;
}
@ -519,12 +554,12 @@ calloc (size_t nmemb, size_t size)
return p;
}
int
islower (int c)
{
return c >= 'a' && c <= 'z';
}
int
isupper (int c)
{

57
scaffold/tests/96-strto.c Normal file
View file

@ -0,0 +1,57 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libmes.h>
#include <stdlib.h>
int
main ()
{
eputs ("0x12\n");
if (strtol ("0x12", 0, 0) != 18)
1;
eputs ("012\n");
if (strtol ("012", 0, 0) != 10)
2;
eputs ("-1\n");
if (strtol ("-1", 0, 0) != -1)
3;
eputs ("-1\n");
if (strtoul ("-1", 0, 0) != -1)
4;
char *p = "16";
int n = strtol (p, (char **)&p, 0);
eputs ("p="); eputs (p); eputs ("\n");
if (*p != 0)
return 5;
p = "0x12";
n = strtol (p, (char **)&p, 0);
eputs ("p="); eputs (p); eputs ("\n");
if (*p != 0)
return 5;
return 0;
}