1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Add strerror_l(3) and strerror_r(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2013-07-11 22:33:54 +02:00
parent 4ac3c313ae
commit a1655ca43b
4 changed files with 78 additions and 6 deletions

View file

@ -116,7 +116,9 @@ string/strcoll.o \
string/strcpy.o \
string/strcspn.o \
string/strdup.o \
string/strerror_l.o \
string/strerror.o \
string/strerror_r.o \
string/strlcpy.o \
string/strlen.o \
string/strncasecmp.o \

View file

@ -50,6 +50,7 @@ int strcoll_l(const char*, const char*, locale_t);
size_t strcspn(const char*, const char*);
char* strcpy(char* __restrict, const char* __restrict);
char* strdup(const char*);
int strerror_r(int, char*, size_t);
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
size_t strlen(const char*);
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_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)
char* strchrnul(const char* str, int c);
#endif
#if defined(_SORTIX_SOURCE)
const char* sortix_strerror(int errnum);
const char* sortix_strerror_l(int, locale_t);
const char* sortix_strsignal(int signum);
#endif
#if defined(_SOURCE_SOURCE) && __SORTIX_STDLIB_REDIRECTS
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");
#else
char* strerror(int errnum);
char* strerror_l(int, locale_t);
char* strsignal(int signum);
#endif

View file

@ -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);
}

View file

@ -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;
}