diff --git a/include/cxx/cstring b/include/cxx/cstring index 038080e75d0..68309195f07 100644 --- a/include/cxx/cstring +++ b/include/cxx/cstring @@ -57,6 +57,7 @@ namespace std using ::strdup; using ::strndup; using ::strerror; + using ::strerror_r; using ::strlen; using ::strnlen; using ::strcat; diff --git a/include/string.h b/include/string.h index 9ba3d03b028..92df7f85b5f 100644 --- a/include/string.h +++ b/include/string.h @@ -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); diff --git a/libc/libc.csv b/libc/libc.csv index 46a193be2cc..fbb8512a583 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -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" diff --git a/libc/string/Make.defs b/libc/string/Make.defs index 415afc9237b..defedcfb60a 100644 --- a/libc/string/Make.defs +++ b/libc/string/Make.defs @@ -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) diff --git a/libc/string/lib_strerrorr.c b/libc/string/lib_strerrorr.c new file mode 100644 index 00000000000..5a19611e251 --- /dev/null +++ b/libc/string/lib_strerrorr.c @@ -0,0 +1,60 @@ +/**************************************************************************** + * libc/string/lib_strerrorr.c + * + * Copyright (C) 2017 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 + +#include +#include + +/**************************************************************************** + * 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; +}