Add wcsto{l,ll,ul,ull,imax,umax}(3).
This commit is contained in:
parent
cba75809fe
commit
8d674a43e1
|
@ -27,6 +27,8 @@ dirent/versionsort.o \
|
|||
errno/errno.o \
|
||||
inttypes/strtoimax.o \
|
||||
inttypes/strtoumax.o \
|
||||
inttypes/wcstoimax.o \
|
||||
inttypes/wcstoumax.o \
|
||||
signal/sigaddset.o \
|
||||
signal/sigdelset.o \
|
||||
signal/sigemptyset.o \
|
||||
|
@ -171,6 +173,10 @@ wchar/wcsrchr.o \
|
|||
wchar/wcsrtombs.o \
|
||||
wchar/wcsspn.o \
|
||||
wchar/wcstok.o \
|
||||
wchar/wcstoll.o \
|
||||
wchar/wcstol.o \
|
||||
wchar/wcstoull.o \
|
||||
wchar/wcstoul.o \
|
||||
wctype/wctype.o \
|
||||
|
||||
HOSTEDOBJS=\
|
||||
|
|
|
@ -204,8 +204,8 @@ intmax_t imaxabs(intmax_t);
|
|||
/* TODO: imaxdiv */
|
||||
intmax_t strtoimax(const char* __restrict, char** __restrict, int);
|
||||
uintmax_t strtoumax(const char* __restrict, char** __restrict, int);
|
||||
/* TODO: wcstoimax */
|
||||
/* TODO: wcstoumax */
|
||||
intmax_t wcstoimax(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
uintmax_t wcstoumax(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef _WCHAR_H
|
||||
#define _WCHAR_H 1
|
||||
#ifndef INCLUDE_WCHAR_H
|
||||
#define INCLUDE_WCHAR_H
|
||||
|
||||
#include <features.h>
|
||||
|
||||
|
@ -78,6 +78,10 @@ wchar_t* wcsrchr(const wchar_t*, wchar_t);
|
|||
size_t wcsrtombs(char* __restrict, const wchar_t** __restrict, size_t, mbstate_t* __restrict);
|
||||
size_t wcsspn(const wchar_t*, const wchar_t*);
|
||||
wchar_t* wcstok(wchar_t* __restrict, const wchar_t* __restrict, wchar_t** __restrict);
|
||||
long long wcstoll(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
long wcstol(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
unsigned long long wcstoull(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
unsigned long wcstoul(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
|
||||
/* TODO: These are not implemented in sortix libc yet. */
|
||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
||||
|
@ -106,12 +110,8 @@ int wmemcmp(const wchar_t*, const wchar_t*, size_t);
|
|||
int wprintf(const wchar_t* __restrict, ...);
|
||||
int wscanf(const wchar_t* __restrict, ...);
|
||||
long double wcstold(const wchar_t* __restrict, wchar_t** __restrict);
|
||||
long long wcstoll(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
long wcstol(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
size_t wcsftime(wchar_t* __restrict, size_t, const wchar_t* __restrict, const struct tm* __restrict);
|
||||
size_t wcsxfrm(wchar_t* __restrict, const wchar_t* __restrict, size_t);
|
||||
unsigned long long wcstoull(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
unsigned long wcstoul(const wchar_t* __restrict, wchar_t** __restrict, int);
|
||||
wchar_t* fgetws(wchar_t* __restrict, int, FILE* __restrict);
|
||||
wchar_t* wcspbrk(const wchar_t*, const wchar_t*);
|
||||
wchar_t* wcsstr(const wchar_t* __restrict, const wchar_t* __restrict);
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#define STRTOL strtoimax
|
||||
#define STRTOL_CHAR char
|
||||
#define STRTOL_L(x) x
|
||||
#define STRTOL_ISSPACE isspace
|
||||
#define STRTOL_INT intmax_t
|
||||
#define STRTOL_UNSIGNED_INT uintmax_t
|
||||
#define STRTOL_INT_MIN INTMAX_MIN
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#define STRTOL strtoumax
|
||||
#define STRTOL_CHAR char
|
||||
#define STRTOL_L(x) x
|
||||
#define STRTOL_ISSPACE isspace
|
||||
#define STRTOL_INT uintmax_t
|
||||
#define STRTOL_UNSIGNED_INT uintmax_t
|
||||
#define STRTOL_INT_MIN 0
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
inttypes/wcstoimax.cpp
|
||||
Converts integers represented as strings to binary representation.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define STRTOL wcstoimax
|
||||
#define STRTOL_CHAR wchar_t
|
||||
#define STRTOL_L(x) L##x
|
||||
#define STRTOL_ISSPACE iswspace
|
||||
#define STRTOL_INT intmax_t
|
||||
#define STRTOL_UNSIGNED_INT uintmax_t
|
||||
#define STRTOL_INT_MIN INTMAX_MIN
|
||||
#define STRTOL_INT_MAX INTMAX_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED false
|
||||
|
||||
#include "../stdlib/strtol.cpp"
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
inttypes/wcstoumax.cpp
|
||||
Converts integers represented as strings to binary representation.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define STRTOL wcstoumax
|
||||
#define STRTOL_CHAR wchar_t
|
||||
#define STRTOL_L(x) L##x
|
||||
#define STRTOL_ISSPACE iswspace
|
||||
#define STRTOL_INT uintmax_t
|
||||
#define STRTOL_UNSIGNED_INT uintmax_t
|
||||
#define STRTOL_INT_MIN 0
|
||||
#define STRTOL_INT_MAX UINTMAX_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED true
|
||||
|
||||
#include "../stdlib/strtol.cpp"
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
#ifndef STRTOL
|
||||
#define STRTOL strtol
|
||||
#define STRTOL_CHAR char
|
||||
#define STRTOL_L(x) x
|
||||
#define STRTOL_ISSPACE isspace
|
||||
#define STRTOL_INT long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long
|
||||
#define STRTOL_INT_MIN LONG_MIN
|
||||
|
@ -38,20 +41,22 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
// Nasty, nasty hack to get LLONG_* macros.
|
||||
#define __STDC_VERSION__ 199901L
|
||||
#include <limits.h>
|
||||
|
||||
// Convert a character into a digit.
|
||||
static int debase(char c)
|
||||
static int debase( STRTOL_CHAR c)
|
||||
{
|
||||
if ( '0' <= c && c <= '9' )
|
||||
return c - '0';
|
||||
if ( 'a' <= c && c <= 'z' )
|
||||
return 10 + c - 'a';
|
||||
if ( 'A' <= c && c <= 'Z' )
|
||||
return 10 + c - 'A';
|
||||
if ( STRTOL_L('0') <= c && c <= STRTOL_L('9') )
|
||||
return c - STRTOL_L('0');
|
||||
if ( STRTOL_L('a') <= c && c <= STRTOL_L('z') )
|
||||
return 10 + c - STRTOL_L('a');
|
||||
if ( STRTOL_L('A') <= c && c <= STRTOL_L('Z') )
|
||||
return 10 + c - STRTOL_L('A');
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -114,36 +119,38 @@ static bool would_multiplication_overflow(T_INT a, T_INT b)
|
|||
}
|
||||
|
||||
extern "C"
|
||||
STRTOL_INT STRTOL(const char* restrict str, char** restrict endptr, int base)
|
||||
STRTOL_INT STRTOL(const STRTOL_CHAR* restrict str,
|
||||
STRTOL_CHAR** restrict endptr,
|
||||
int base)
|
||||
{
|
||||
const char* origstr = str;
|
||||
const STRTOL_CHAR* origstr = str;
|
||||
int origbase = base;
|
||||
|
||||
// Skip any leading white space.
|
||||
while ( isspace(*str) )
|
||||
while ( STRTOL_ISSPACE(*str) )
|
||||
str++;
|
||||
|
||||
// Reject bad bases.
|
||||
if ( base < 0 || 36 < base )
|
||||
{
|
||||
if ( endptr )
|
||||
*endptr = (char*) str;
|
||||
*endptr = (STRTOL_CHAR*) str;
|
||||
return errno = EINVAL, 0;
|
||||
}
|
||||
|
||||
bool negative = false;
|
||||
char c = *str;
|
||||
STRTOL_CHAR c = *str;
|
||||
|
||||
// Handle a leading sign character.
|
||||
if ( c == '-' )
|
||||
if ( c == STRTOL_L('-') )
|
||||
str++, negative = true;
|
||||
if ( c == '+' )
|
||||
if ( c == STRTOL_L('+') )
|
||||
str++, negative = false;
|
||||
|
||||
// Autodetect base 8 or base 16.
|
||||
if ( !base && str[0] == '0' )
|
||||
if ( !base && str[0] == STRTOL_L('0') )
|
||||
{
|
||||
if ( str[1] == 'x' || str[1] == 'X' )
|
||||
if ( str[1] == STRTOL_L('x') || str[1] == STRTOL_L('X') )
|
||||
str += 2, base = 16;
|
||||
else if ( 0 <= debase(str[1]) && debase(str[1]) < 8 )
|
||||
str++, base = 8;
|
||||
|
@ -154,7 +161,9 @@ STRTOL_INT STRTOL(const char* restrict str, char** restrict endptr, int base)
|
|||
base = 10;
|
||||
|
||||
// Skip the leading '0x' prefix in base 16 for hexadecimal integers.
|
||||
if ( origbase == 16 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
|
||||
if ( origbase == 16 &&
|
||||
str[0] == STRTOL_L('0') &&
|
||||
(str[1] == STRTOL_L('x') || str[1] == STRTOL_L('X')) )
|
||||
str += 2;
|
||||
|
||||
// Determine what value will be returned on overflow/underflow.
|
||||
|
@ -213,7 +222,7 @@ STRTOL_INT STRTOL(const char* restrict str, char** restrict endptr, int base)
|
|||
|
||||
// Let the caller know where we got to.
|
||||
if ( endptr )
|
||||
*endptr = (char*) str;
|
||||
*endptr = (STRTOL_CHAR*) str;
|
||||
|
||||
// Handle the special case where we are creating an unsigned integer and the
|
||||
// string was negative and non-zero and no overflow occured, then we treat
|
||||
|
|
|
@ -23,10 +23,13 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#define STRTOL strtoll
|
||||
#define STRTOL_CHAR char
|
||||
#define STRTOL_L(x) x
|
||||
#define STRTOL_ISSPACE isspace
|
||||
#define STRTOL_INT long long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long long
|
||||
#define STRTOL_INT_MIN LLONG_MIN
|
||||
#define STRTOL_INT_MAX LLONG_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED true
|
||||
#define STRTOL_INT_IS_UNSIGNED false
|
||||
|
||||
#include "strtol.cpp"
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#define STRTOL strtoul
|
||||
#define STRTOL_CHAR char
|
||||
#define STRTOL_L(x) x
|
||||
#define STRTOL_ISSPACE isspace
|
||||
#define STRTOL_INT unsigned long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long
|
||||
#define STRTOL_INT_MIN 0
|
||||
|
|
|
@ -23,6 +23,9 @@
|
|||
*******************************************************************************/
|
||||
|
||||
#define STRTOL strtoull
|
||||
#define STRTOL_CHAR char
|
||||
#define STRTOL_L(x) x
|
||||
#define STRTOL_ISSPACE isspace
|
||||
#define STRTOL_INT unsigned long long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long long
|
||||
#define STRTOL_INT_MIN 0
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
wchar/wcstol.cpp
|
||||
Converts integers represented as strings to binary representation.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define STRTOL wcstol
|
||||
#define STRTOL_CHAR wchar_t
|
||||
#define STRTOL_L(x) L##x
|
||||
#define STRTOL_ISSPACE iswspace
|
||||
#define STRTOL_INT long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long
|
||||
#define STRTOL_INT_MIN LONG_MIN
|
||||
#define STRTOL_INT_MAX LONG_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED false
|
||||
|
||||
#include "../stdlib/strtol.cpp"
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
wchar/wcstoll.cpp
|
||||
Converts integers represented as strings to binary representation.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define STRTOL wcstoll
|
||||
#define STRTOL_CHAR wchar_t
|
||||
#define STRTOL_L(x) L##x
|
||||
#define STRTOL_ISSPACE iswspace
|
||||
#define STRTOL_INT long long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long long
|
||||
#define STRTOL_INT_MIN LLONG_MIN
|
||||
#define STRTOL_INT_MAX LLONG_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED false
|
||||
|
||||
#include "../stdlib/strtol.cpp"
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
wchar/wcstoul.cpp
|
||||
Converts integers represented as strings to binary representation.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define STRTOL wcstoul
|
||||
#define STRTOL_CHAR wchar_t
|
||||
#define STRTOL_L(x) L##x
|
||||
#define STRTOL_ISSPACE iswspace
|
||||
#define STRTOL_INT unsigned long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long
|
||||
#define STRTOL_INT_MIN 0
|
||||
#define STRTOL_INT_MAX ULONG_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED true
|
||||
|
||||
#include "../stdlib/strtol.cpp"
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
|
||||
Copyright(C) Jonas 'Sortie' Termansen 2013.
|
||||
|
||||
This file is part of the Sortix C Library.
|
||||
|
||||
The Sortix C Library is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your
|
||||
option) any later version.
|
||||
|
||||
The Sortix C Library 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 Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
wchar/wcstoull.cpp
|
||||
Converts integers represented as strings to binary representation.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#define STRTOL wcstoull
|
||||
#define STRTOL_CHAR wchar_t
|
||||
#define STRTOL_L(x) L##x
|
||||
#define STRTOL_ISSPACE iswspace
|
||||
#define STRTOL_INT unsigned long long
|
||||
#define STRTOL_UNSIGNED_INT unsigned long long
|
||||
#define STRTOL_INT_MIN 0
|
||||
#define STRTOL_INT_MAX ULLONG_MAX
|
||||
#define STRTOL_INT_IS_UNSIGNED true
|
||||
|
||||
#include "../stdlib/strtol.cpp"
|
Loading…
Reference in New Issue