Add strerror_l(3) and strerror_r(3).
This commit is contained in:
parent
4ac3c313ae
commit
a1655ca43b
|
@ -116,7 +116,9 @@ string/strcoll.o \
|
||||||
string/strcpy.o \
|
string/strcpy.o \
|
||||||
string/strcspn.o \
|
string/strcspn.o \
|
||||||
string/strdup.o \
|
string/strdup.o \
|
||||||
|
string/strerror_l.o \
|
||||||
string/strerror.o \
|
string/strerror.o \
|
||||||
|
string/strerror_r.o \
|
||||||
string/strlcpy.o \
|
string/strlcpy.o \
|
||||||
string/strlen.o \
|
string/strlen.o \
|
||||||
string/strncasecmp.o \
|
string/strncasecmp.o \
|
||||||
|
|
|
@ -50,6 +50,7 @@ int strcoll_l(const char*, const char*, locale_t);
|
||||||
size_t strcspn(const char*, const char*);
|
size_t strcspn(const char*, const char*);
|
||||||
char* strcpy(char* __restrict, const char* __restrict);
|
char* strcpy(char* __restrict, const char* __restrict);
|
||||||
char* strdup(const char*);
|
char* strdup(const char*);
|
||||||
|
int strerror_r(int, char*, size_t);
|
||||||
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
|
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
char* strncat(char* __restrict, const char* __restrict, size_t);
|
char* strncat(char* __restrict, const char* __restrict, size_t);
|
||||||
|
@ -67,25 +68,22 @@ int strverscmp(const char*, const char*);
|
||||||
size_t strxfrm(char* __restrict, const char* __restrict, size_t);
|
size_t strxfrm(char* __restrict, const char* __restrict, size_t);
|
||||||
size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
|
size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
|
||||||
|
|
||||||
/* TODO: These are not implemented in sortix libc yet. */
|
|
||||||
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
|
||||||
char* strerror_l(int, locale_t);
|
|
||||||
int strerror_r(int, char*, size_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_SORTIX_SOURCE) || defined(_GNU_SOURCE)
|
#if defined(_SORTIX_SOURCE) || defined(_GNU_SOURCE)
|
||||||
char* strchrnul(const char* str, int c);
|
char* strchrnul(const char* str, int c);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_SORTIX_SOURCE)
|
#if defined(_SORTIX_SOURCE)
|
||||||
const char* sortix_strerror(int errnum);
|
const char* sortix_strerror(int errnum);
|
||||||
|
const char* sortix_strerror_l(int, locale_t);
|
||||||
const char* sortix_strsignal(int signum);
|
const char* sortix_strsignal(int signum);
|
||||||
#endif
|
#endif
|
||||||
#if defined(_SOURCE_SOURCE) && __SORTIX_STDLIB_REDIRECTS
|
#if defined(_SOURCE_SOURCE) && __SORTIX_STDLIB_REDIRECTS
|
||||||
const char* strerror(int errnum) asm ("sortix_strerror");
|
const char* strerror(int errnum) asm ("sortix_strerror");
|
||||||
|
const char* strerror_l(int, locale_t) asm ("sortix_strerror_l");
|
||||||
const char* strsignal(int signum) asm ("sortix_strsignal");
|
const char* strsignal(int signum) asm ("sortix_strsignal");
|
||||||
#else
|
#else
|
||||||
char* strerror(int errnum);
|
char* strerror(int errnum);
|
||||||
|
char* strerror_l(int, locale_t);
|
||||||
char* strsignal(int signum);
|
char* strsignal(int signum);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
string/strerror_l.cpp
|
||||||
|
Convert error code to a string.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern "C" const char* sortix_strerror_l(int errnum, locale_t /*locale*/)
|
||||||
|
{
|
||||||
|
return sortix_strerror(errnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" char* strerror_l(int errnum, locale_t locale)
|
||||||
|
{
|
||||||
|
return (char*) sortix_strerror_l(errnum, locale);
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 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/>.
|
||||||
|
|
||||||
|
string/strerror_r.cpp
|
||||||
|
Convert error code to a string.
|
||||||
|
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern "C" int strerror_r(int errnum, char* dest, size_t dest_len)
|
||||||
|
{
|
||||||
|
const char* msg = sortix_strerror(errnum);
|
||||||
|
if ( !msg )
|
||||||
|
return -1;
|
||||||
|
if ( strlcpy(dest, msg, dest_len) != strlen(msg) )
|
||||||
|
errno = ERANGE;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue