C library: Add strerror_r

This commit is contained in:
Gregory Nutt
2017-03-08 12:14:07 -06:00
parent 9a76a6de26
commit 05a288f2e1
5 changed files with 67 additions and 4 deletions
+1
View File
@@ -57,6 +57,7 @@ namespace std
using ::strdup;
using ::strndup;
using ::strerror;
using ::strerror_r;
using ::strlen;
using ::strnlen;
using ::strcat;
+4 -3
View File
@@ -64,6 +64,7 @@ extern "C"
FAR char *strdup(FAR const char *s);
FAR char *strndup(FAR const char *s, size_t size);
FAR const char *strerror(int);
int strerror_r(int, FAR char *, size_t);
size_t strlen(FAR const char *);
size_t strnlen(FAR const char *, size_t);
FAR char *strcat(FAR char *, FAR const char *);
@@ -71,9 +72,9 @@ FAR char *strncat(FAR char *, FAR const char *, size_t);
int strcmp(FAR const char *, FAR const char *);
int strncmp(FAR const char *, FAR const char *, size_t);
int strcoll(FAR const char *, FAR const char *s2);
FAR char *strcpy(char *dest, FAR const char *src);
FAR char *stpcpy(char *dest, FAR const char *src);
FAR char *strncpy(char *, FAR const char *, size_t);
FAR char *strcpy(FAR char *dest, FAR const char *src);
FAR char *stpcpy(FAR char *dest, FAR const char *src);
FAR char *strncpy(FAR char *, FAR const char *, size_t);
FAR char *strpbrk(FAR const char *, FAR const char *);
FAR char *strchr(FAR const char *s, int c);
FAR char *strrchr(FAR const char *s, int c);
+1
View File
@@ -154,6 +154,7 @@
"strcspn","string.h","","size_t","FAR const char *","FAR const char *"
"strdup","string.h","","FAR char","FAR const char *"
"strerror","string.h","","FAR const char","int"
"strerror_r","string.h","","int","int", "FAR char *", "size_t"
"strftime","time.h","","size_t","FAR char *","size_t","FAR const char *","FAR const struct tm *"
"strlen","string.h","","size_t","FAR const char *"
"strncasecmp","strings.h","","int","FAR const char *","FAR const char *","size_t"
Can't render this file because it contains an unexpected character in line 82 and column 22.
+1 -1
View File
@@ -42,7 +42,7 @@ CSRCS += lib_strcpy.c lib_strcmp.c lib_strcspn.c lib_strdup.c
CSRCS += lib_strerror.c lib_strlen.c lib_strnlen.c lib_strncasecmp.c
CSRCS += lib_strncat.c lib_strncmp.c lib_strncpy.c lib_strndup.c
CSRCS += lib_strcasestr.c lib_strpbrk.c lib_strrchr.c lib_strspn.c
CSRCS += lib_strstr.c lib_strtok.c lib_strtokr.c
CSRCS += lib_strstr.c lib_strtok.c lib_strtokr.c lib_strerrorr.c
ifneq ($(CONFIG_LIBC_ARCH_MEMCPY),y)
ifeq ($(CONFIG_MEMCPY_VIK),y)
+60
View File
@@ -0,0 +1,60 @@
/****************************************************************************
* libc/string/lib_strerrorr.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <string.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: strerror_r
****************************************************************************/
int strerror_r(int errnum, FAR char *buf, size_t buflen)
{
FAR const char *errstr = strerror(errnum);
DEBUGASSERT(buf != NULL);
strncpy(buf, errstr, buflen);
return OK;
}