fxlibc/src/stdlib/stdlib_p.h
Lephenixnoir b11c059c0f
stdio: start simplifying scanf limit tracking logic
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.
2024-01-14 19:28:36 +01:00

53 lines
1.6 KiB
C

#ifndef __STDLIB_P_H__
# define __STDLIB_P_H__
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#include "../stdio/stdio_p.h"
/*
** Parse an integer from a string. This is the base function for strtol,
** strtoul, strtoll, and strtoull.
**
** This function does not set errno, and instead returns the error code
** according to conversion rules. Setting errno is troublesome because it's a
** global state that cannot be reverted and thus cannot be tested.
**
** If outl is non-NULL, strto_int produces a long or an unsigned long result
** (depending on use_unsigned). Signedness only affects the range of values
** that are considered to be ERANGE, and both results are stored in *outl.
** Similarly, if outll is non-NULL, strto_int produces a long long or unsigned
** long long result. Only one pointer should be non-NULL.
**
** On platforms where long is 32-bit, 64-bit operations are performed only if
** outll is non-NULL. This is because multiplications with overflow can be
** expensive.
**
** N is the bound on the number of characters to read. To disable the bound,
** specify INT_MAX.
*/
int __strto_int(
struct __scanf_input *__input,
int __base,
long *__outl,
long long *__outll,
bool __use_unsigned,
int __N);
/*
** Parse a floating-point value from a string. This is the base function for
** strtod, strtof, and strtold.
**
** This function is similar to strto_int(). If returns the error code to set in
** errno, and can produce one of three outputs depending on which of out, outf
** and outl is set.
*/
int __strto_fp(
struct __scanf_input *__input,
double *__out,
float *__outf,
long double *__outl,
int __N);
#endif /*__STDLIB_P_H__*/