mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2025-05-28 22:45:15 +02:00
Basically removing it from the __scanf_input structure and specializing it at format sites. The reason is that pretending it's the end of the stream after the limit is reached does not work because we have to return EOF at end of stream but not when the limit is hit. So we have to handle it explicitly, and since we do, no need to have it in the structure too.
20 lines
453 B
C
20 lines
453 B
C
#include "stdlib_p.h"
|
|
#include <errno.h>
|
|
|
|
long int strtol(char const * restrict ptr, char ** restrict endptr, int base)
|
|
{
|
|
long n = 0;
|
|
if(endptr)
|
|
*endptr = (char *)ptr;
|
|
|
|
struct __scanf_input in = { .str = ptr, .fp = NULL };
|
|
__scanf_start(&in);
|
|
int err = __strto_int(&in, base, &n, NULL, false, INT_MAX);
|
|
__scanf_end(&in);
|
|
|
|
if(err != 0)
|
|
errno = (err == EOF) ? EINVAL : err;
|
|
if(err != EINVAL && endptr)
|
|
*endptr = (char *)in.str;
|
|
return n;
|
|
}
|