mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[libc] Bring libc in-tree
Moving libc from its separate repo into this one, minor resulting build fixes, and a hacky way to add -I for libc headers in builds.
This commit is contained in:
42
src/libraries/libc/j6libc/strtox_main.c
Normal file
42
src/libraries/libc/j6libc/strtox_main.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* _PDCLIB_strtox_main( const char * *, int, uintmax_t, uintmax_t, int )
|
||||
|
||||
This file is part of the Public Domain C Library (PDCLib).
|
||||
Permission is granted to use, modify, and / or redistribute at will.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintmax_t error, uintmax_t limval, int limdigit, char * sign )
|
||||
{
|
||||
uintmax_t rc = 0;
|
||||
int digit = -1;
|
||||
const char * x;
|
||||
while ( ( x = memchr( _PDCLIB_digits, tolower(**p), base ) ) != NULL )
|
||||
{
|
||||
digit = x - _PDCLIB_digits;
|
||||
if ( ( rc < limval ) || ( ( rc == limval ) && ( digit <= limdigit ) ) )
|
||||
{
|
||||
rc = rc * base + (unsigned)digit;
|
||||
++(*p);
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = ERANGE;
|
||||
/* TODO: Only if endptr != NULL - but do we really want *another* parameter? */
|
||||
/* TODO: Earlier version was missing tolower() here but was not caught by tests */
|
||||
while ( memchr( _PDCLIB_digits, tolower(**p), base ) != NULL ) ++(*p);
|
||||
/* TODO: This is ugly, but keeps caller from negating the error value */
|
||||
*sign = '+';
|
||||
return error;
|
||||
}
|
||||
}
|
||||
if ( digit == -1 )
|
||||
{
|
||||
*p = NULL;
|
||||
return 0;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
Reference in New Issue
Block a user