From 4d39b513b585be5d148c4fd4b8c361de136abd3e Mon Sep 17 00:00:00 2001 From: Alan Carvalho de Assis Date: Tue, 18 Oct 2016 18:15:54 -0600 Subject: [PATCH] Add functions wcrtomb, wcslcpy, wcsxfrm, wctob, wctomb, wctype, localeconv, strcoll, strxfrm --- include/locale.h | 6 ++ include/string.h | 4 +- libc/Kconfig | 6 ++ libc/libc.csv | 80 +++++++++++--------- libc/locale/Make.defs | 4 + libc/locale/lib_localeconv.c | 69 +++++++++++++++++ libc/locale/lib_setlocale.c | 3 + libc/string/Make.defs | 6 +- libc/string/lib_strcoll.c | 59 +++++++++++++++ libc/string/lib_strxfrm.c | 80 ++++++++++++++++++++ libc/wchar/Make.defs | 8 +- libc/wchar/lib_btowc.c | 3 +- libc/wchar/lib_mbrtowc.c | 3 +- libc/wchar/lib_mbtowc.c | 3 +- libc/wchar/lib_wcrtomb.c | 81 ++++++++++++++++++++ libc/wchar/lib_wcscmp.c | 3 +- libc/wchar/lib_wcscoll.c | 3 +- libc/wchar/lib_wcslcpy.c | 93 +++++++++++++++++++++++ libc/wchar/lib_wcslen.c | 3 +- libc/wchar/lib_wcsxfrm.c | 62 +++++++++++++++ libc/wchar/lib_wctob.c | 68 +++++++++++++++++ libc/wchar/lib_wctomb.c | 75 ++++++++++++++++++ libc/wchar/lib_wctype.c | 143 +++++++++++++++++++++++++++++++++++ libc/wchar/lib_wmemchr.c | 3 +- libc/wchar/lib_wmemcmp.c | 3 +- libc/wchar/lib_wmemcpy.c | 3 +- libc/wchar/lib_wmemmove.c | 3 +- libc/wchar/lib_wmemset.c | 3 +- 28 files changed, 830 insertions(+), 50 deletions(-) create mode 100644 libc/locale/lib_localeconv.c create mode 100644 libc/string/lib_strcoll.c create mode 100644 libc/string/lib_strxfrm.c create mode 100644 libc/wchar/lib_wcrtomb.c create mode 100644 libc/wchar/lib_wcslcpy.c create mode 100644 libc/wchar/lib_wcsxfrm.c create mode 100644 libc/wchar/lib_wctob.c create mode 100644 libc/wchar/lib_wctomb.c create mode 100644 libc/wchar/lib_wctype.c diff --git a/include/locale.h b/include/locale.h index 2d61f8d7537..32f97b2dc11 100644 --- a/include/locale.h +++ b/include/locale.h @@ -42,10 +42,14 @@ #include +#ifdef CONFIG_LIBC_LOCALE + /**************************************************************************** * Type Definitions ****************************************************************************/ +struct lconv; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -59,10 +63,12 @@ extern "C" #endif FAR char *setlocale(int category, FAR const char *locale); +FAR struct lconv *localeconv(void); #undef EXTERN #ifdef __cplusplus } #endif +#endif /* CONFIG_LIBC_LOCALE */ #endif /* __INCLUDE_LOCALE_H */ diff --git a/include/string.h b/include/string.h index 396f440872c..351a9da0e73 100644 --- a/include/string.h +++ b/include/string.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/string.h * - * Copyright (C) 2007-2012, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2012, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -79,6 +79,7 @@ int strcmp(FAR const char *, FAR const char *); int strncmp(FAR const char *, FAR const char *, size_t); int strcasecmp(FAR const char *, FAR const char *); int strncasecmp(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); @@ -91,6 +92,7 @@ FAR char *strstr(FAR const char *, FAR const char *); FAR char *strcasestr(FAR const char *, FAR const char *); FAR char *strtok(FAR char *, FAR const char *); FAR char *strtok_r(FAR char *, FAR const char *, FAR char **); +size_t strxfrm(FAR char *, FAR const char *, size_t n); FAR void *memchr(FAR const void *s, int c, size_t n); FAR void *memccpy(FAR void *s1, FAR const void *s2, int c, size_t n); diff --git a/libc/Kconfig b/libc/Kconfig index 6df979b0ce1..dead1df0b34 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -110,6 +110,12 @@ config LIBC_WCHAR ---help--- By default, wide-characters support is disabled. +config LIBC_LOCALE + bool "Enable I18N (LOCALE) support" + default n + ---help--- + By default, i18n (locale) support is disabled. + config LIB_RAND_ORDER int "Order of the random number generate" default 1 diff --git a/libc/libc.csv b/libc/libc.csv index 327b796d32b..c150080de94 100644 --- a/libc/libc.csv +++ b/libc/libc.csv @@ -4,8 +4,8 @@ "aio_error","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *" "aio_return","aio.h","defined(CONFIG_FS_AIO)","ssize_t","FAR struct aiocb *" "aio_suspend","aio.h","defined(CONFIG_FS_AIO)","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR const struct timespec *" -"asprintf","stdio.h","","int","FAR char **","const char *","..." -"vasprintf","stdio.h","","int","FAR char **","const char *","va_list" +"asprintf","stdio.h","","int","FAR char **","FAR const char *","..." +"vasprintf","stdio.h","","int","FAR char **","FAR const char *","va_list" "b16atan2","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" "b16cos","fixedmath.h","","b16_t","b16_t" "b16divb16","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","b16_t","b16_t","b16_t" @@ -26,7 +26,7 @@ "dq_rem","queue.h","","void","FAR dq_entry_t *","dq_queue_t *" "dq_remfirst","queue.h","","FAR dq_entry_t","dq_queue_t *" "dq_remlast","queue.h","","FAR dq_entry_t","dq_queue_t *" -"_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","int","const char *","..." +"_err","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_ERROR)","int","FAR const char *","..." "ether_ntoa","netinet/ether.h","","FAR char","FAR const struct ether_addr *" "fclose","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *" "fdopen","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR FILE","int","FAR const char *" @@ -51,7 +51,7 @@ "getoptindp","unistd.h","","int" "getoptoptp","unistd.h","","int" "gets","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","FAR char","FAR char *" -"gmtime","time.h","","struct tm","const time_t *" +"gmtime","time.h","","struct tm","FAR const time_t *" "gmtime_r","time.h","","FAR struct tm","FAR const time_t *","FAR struct tm *" "htonl","arpa/inet.h","","uint32_t","uint32_t" "htons","arpa/inet.h","","uint16_t","uint16_t" @@ -64,9 +64,9 @@ "lib_dumpbuffer","debug.h","","void","FAR const char *","FAR const uint8_t *","unsigned int" "lio_listio","aio.h","defined(CONFIG_FS_AIO)","int","int","FAR struct aiocb *const []|FAR struct aiocb *const *","int","FAR struct sigevent *" "llabs","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long int","long long int" -"match","nuttx/lib/regex.h","","int","const char *","const char *" -"mbrtowc","wchar.h",""defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","const char *", "size_t", "mbstate_t *" -"mbtowc","wchar.h",""defined(CONFIG_LIBC_WCHAR)","int","wchar_t *","const wchar_t *", "size_t" +"match","nuttx/lib/regex.h","","int","FAR const char *","FAR const char *" +"mbrtowc","wchar.h",""defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","FAR const char *","size_t","mbstate_t *" +"mbtowc","wchar.h",""defined(CONFIG_LIBC_WCHAR)","int","wchar_t *","FAR const wchar_t *","size_t" "memccpy","string.h","","FAR void","FAR void *","FAR const void *","int c","size_t" "memchr","string.h","","FAR void","FAR const void *","int c","size_t" "memcmp","string.h","","int","FAR const void *","FAR const void *","size_t" @@ -74,12 +74,12 @@ "memmove","string.h","","FAR void","FAR void *","FAR const void *","size_t" "memset","string.h","","FAR void","FAR void *","int c","size_t" "mkfifo","sys/stat.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR const char*","mode_t" -"mktime","time.h","","time_t","const struct tm *" +"mktime","time.h","","time_t","FAR const struct tm *" "ntohl","arpa/inet.h","","uint32_t","uint32_t" "ntohs","arpa/inet.h","","uint16_t","uint16_t" "perror","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","void","FAR const char *" "pipe","unistd.h","CONFIG_NFILE_DESCRIPTORS > 0","int","int [2]|int*" -"printf","stdio.h","","int","const char *","..." +"printf","stdio.h","","int","FAR const char *","..." "pthread_attr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *" "pthread_attr_getinheritsched","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR const pthread_attr_t *","FAR int *" "pthread_attr_getschedparam","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_attr_t *","FAR struct sched_param *" @@ -98,12 +98,12 @@ "pthread_condattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_condattr_t *" "pthread_mutexattr_destroy","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" "pthread_mutexattr_getpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","FAR int *" -"pthread_mutexattr_gettype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","const pthread_mutexattr_t *","int *" +"pthread_mutexattr_gettype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","FAR const pthread_mutexattr_t *","int *" "pthread_mutexattr_init","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *" "pthread_mutexattr_setpshared","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_mutexattr_t *","int " "pthread_mutexattr_settype","pthread.h","!defined(CONFIG_DISABLE_PTHREAD) && defined(CONFIG_MUTEX_TYPES)","int","pthread_mutexattr_t *","int" "puts","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *" -"qsort","stdlib.h","","void","void *","size_t","size_t","int(*)(const void *","const void *)" +"qsort","stdlib.h","","void","void *","size_t","size_t","int(*)(const void *","FAR const void *)" "rand","stdlib.h","","int" "readdir_r","dirent.h","CONFIG_NFILE_DESCRIPTORS > 0","int","FAR DIR *","FAR struct dirent *","FAR struct dirent **" "sched_get_priority_max","sched.h","","int","int" @@ -119,8 +119,8 @@ "sigfillset","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR sigset_t *" "sigismember","signal.h","!defined(CONFIG_DISABLE_SIGNALS)","int","FAR const sigset_t *","int" "sleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","unsigned int","unsigned int" -"snprintf","stdio.h","","int","FAR char *","size_t","const char *","..." -"sprintf","stdio.h","","int","FAR char *","const char *","..." +"snprintf","stdio.h","","int","FAR char *","size_t","FAR const char *","..." +"sprintf","stdio.h","","int","FAR char *","FAR const char *","..." "sq_addafter","queue.h","","void","FAR sq_entry_t *","FAR sq_entry_t *","FAR sq_queue_t *" "sq_addfirst","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" "sq_addlast","queue.h","","void","FAR sq_entry_t *","sq_queue_t *" @@ -129,35 +129,37 @@ "sq_remfirst","queue.h","","FAR sq_entry_t","sq_queue_t *" "sq_remlast","queue.h","","FAR sq_entry_t","sq_queue_t *" "srand","stdlib.h","","void","unsigned int" -"sscanf","stdio.h","","int","const char *","const char *","..." +"sscanf","stdio.h","","int","FAR const char *","FAR const char *","..." "strcasecmp","string.h","","int","FAR const char *","FAR const char *" "strcasestr","string.h","","FAR char","FAR const char *","FAR const char *" "strcat","string.h","","FAR char","FAR char *","FAR const char *" "strchr","string.h","","FAR char","FAR const char *","int" "strcmp","string.h","","int","FAR const char *","FAR const char *" -"strcpy","string.h","","FAR char","char *","FAR const char *" +"strcoll","string.h","CONFIG_LIBC_LOCALE","int","FAR const char *","FAR const char *" +"strcpy","string.h","","FAR char *","FAR char *","FAR const char *" "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" -"strftime","time.h","","size_t","char *","size_t","const char *","const struct tm *" +"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","string.h","","int","FAR const char *","FAR const char *","size_t" "strncat","string.h","","FAR char","FAR char *","FAR const char *","size_t" "strncmp","string.h","","int","FAR const char *","FAR const char *","size_t" -"strncpy","string.h","","FAR char","char *","FAR const char *","size_t" +"strncpy","string.h","","FAR char","FAR char *","FAR const char *","size_t" "strndup","string.h","","FAR char","FAR const char *","size_t" "strnlen","string.h","","size_t","FAR const char *","size_t" "strpbrk","string.h","","FAR char","FAR const char *","FAR const char *" "strrchr","string.h","","FAR char","FAR const char *","int" "strspn","string.h","","size_t","FAR const char *","FAR const char *" "strstr","string.h","","FAR char","FAR const char *","FAR const char *" -"strtod","stdlib.h","","double_t","const char *str","char **endptr" +"strtod","stdlib.h","","double_t","FAR const char *str","FAR char **endptr" "strtok","string.h","","FAR char","FAR char *","FAR const char *" "strtok_r","string.h","","FAR char","FAR char *","FAR const char *","FAR char **" -"strtol","string.h","","long","const char *","char **","int" -"strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","const char *nptr","char **endptr","int base" -"strtoul","stdlib.h","","unsigned long","const char *","char **","int" -"strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","const char *","char **","int" +"strtol","string.h","","long","FAR const char *","FAR char **","int" +"strtoll","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","long long","FAR const char *nptr","FAR char **endptr","int base" +"strtoul","stdlib.h","","unsigned long","FAR const char *","FAR char **","int" +"strtoull","stdlib.h","defined(CONFIG_HAVE_LONG_LONG)","unsigned long long","FAR const char *","FAR char **","int" +"strxfrm","string.h","defined(CONFIG_LIBC_LOCALE)","size_t","FAR char *","FAR const char *","size_t" "syslog","syslog.h","","int","int","FAR const char *","..." "tcflush","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","int" "tcgetattr","termios.h","CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_SERIAL_TERMIOS)","int","int","FAR struct termios *" @@ -169,19 +171,25 @@ "ub16sqr","fixedmath.h","!defined(CONFIG_HAVE_LONG_LONG)","ub16_t","ub16_t" "ungetc","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","int","FAR FILE *" "usleep","unistd.h","!defined(CONFIG_DISABLE_SIGNALS)","int","int","FAR FILE *" -"_info","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO)","int","const char *","..." -"vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","const char *","va_list" +"_info","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_INFO)","int","FAR const char *","..." +"vfprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR FILE *","FAR const char *","va_list" "vprintf","stdio.h","CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0","int","FAR const char *","va_list" -"vsnprintf","stdio.h","","int","FAR char *","size_t","const char *","va_list" -"vsprintf","stdio.h","","int","FAR char *","const char *","va_list" -"vsscanf","stdio.h","","int","char *","const char *","va_list" +"vsnprintf","stdio.h","","int","FAR char *","size_t","FAR const char *","va_list" +"vsprintf","stdio.h","","int","FAR char *","FAR const char *","va_list" +"vsscanf","stdio.h","","int","FAR char *","FAR const char *","va_list" "vsyslog","syslog.h","","int","int","FAR const char *","va_list" -"wcscmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int", "const wchar_t *", "const wchar_t *" -"wcscoll","wchar.h","defined(CONFIG_LIBC_WCHAR)","int", "const wchar_t *", "const wchar_t *" -"wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t", "const wchar_t *" -"wmemchr","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchar_t *", "wchar_t *", "wchar_t", "size_t" -"wmemcmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int", "wchar_t *", "wchar_t *", "size_t" -"wmemcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *", "wchar_t *", "wchar_t *", "size_t" -"wmemmove","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *", "wchar_t *", "wchar_t *", "size_t" -"wmemset","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *", "wchar_t *", "wchar_t", "size_t" -"_warn","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN)","int","const char *","..." +"wcrtomb","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR char *","wchar_t","mbstate_t *" +"wcscmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *" +"wcscoll","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR const wchar_t *","FAR const wchar_t *" +"wcslcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *","FAR const wchar_t *","size_t" +"wcslen","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","FAR const wchar_t *" +"wcsxfrm","wchar.h","defined(CONFIG_LIBC_WCHAR)","size_t","wchar_t *","FAR const wchar_t *","size_t" +"wctob","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","wchar_t" +"wctomb","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","FAR char *","wchar_t" +"wctype","wctype.h","defined(CONFIG_LIBC_WCHAR)","wctype_t","FAR const char *" +"wmemchr","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchar_t *","wchar_t *","wchar_t","size_t" +"wmemcmp","wchar.h","defined(CONFIG_LIBC_WCHAR)","int","wchar_t *","wchar_t *","size_t" +"wmemcpy","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *","wchar_t *","wchar_t *","size_t" +"wmemmove","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *","wchar_t *","wchar_t *","size_t" +"wmemset","wchar.h","defined(CONFIG_LIBC_WCHAR)","wchat_t *","wchar_t *","wchar_t","size_t" +"_warn","debug.h","!defined(CONFIG_CPP_HAVE_VARARGS) && defined(CONFIG_DEBUG_WARN)","int","FAR const char *","..." diff --git a/libc/locale/Make.defs b/libc/locale/Make.defs index a7a40e190b9..bbf9c6a33db 100644 --- a/libc/locale/Make.defs +++ b/libc/locale/Make.defs @@ -33,6 +33,8 @@ # ############################################################################ +ifeq ($(CONFIG_LIBC_LOCALE),y) + # Add the locale files to the build CSRCS += lib_setlocale.c @@ -41,3 +43,5 @@ CSRCS += lib_setlocale.c DEPPATH += --dep-path locale VPATH += :locale + +endif diff --git a/libc/locale/lib_localeconv.c b/libc/locale/lib_localeconv.c new file mode 100644 index 00000000000..3238dfa10a9 --- /dev/null +++ b/libc/locale/lib_localeconv.c @@ -0,0 +1,69 @@ +/**************************************************************************** + * libc/locale/lib_localeconv.c + * + * Copyright (C) 2016 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 + +#ifdef CONFIG_LIBC_LOCALE + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: localeconv + * + * Description: + * locales are not supported by NuttX + * + * Input Parameters: + * category and locale - Select the appropriate piece of the program's + * locale. + * + ****************************************************************************/ + +FAR struct lconv *localeconv(void); +{ + /* NULL indicates the the locale was not changed */ + + return NULL; +} +#endif diff --git a/libc/locale/lib_setlocale.c b/libc/locale/lib_setlocale.c index 8f5fffd62e9..335eda84e49 100644 --- a/libc/locale/lib_setlocale.c +++ b/libc/locale/lib_setlocale.c @@ -42,6 +42,8 @@ #include #include +#ifdef CONFIG_LIBC_LOCALE + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -64,3 +66,4 @@ FAR char *setlocale(int category, FAR const char *locale) return NULL; } +#endif diff --git a/libc/string/Make.defs b/libc/string/Make.defs index ff0ca1f6bff..beac5ac4de0 100644 --- a/libc/string/Make.defs +++ b/libc/string/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # libc/string/Make.defs # -# Copyright (C) 2011-2012, 2014 Gregory Nutt. All rights reserved. +# Copyright (C) 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -51,6 +51,10 @@ CSRCS += lib_memcpy.c endif endif +ifeq ($(CONFIG_LIBC_LOCALE),y) +CSRCS += lib_strcoll.c lib_strxfrm.c +endif + # Add the string directory to the build DEPPATH += --dep-path string diff --git a/libc/string/lib_strcoll.c b/libc/string/lib_strcoll.c new file mode 100644 index 00000000000..25d274dc8e0 --- /dev/null +++ b/libc/string/lib_strcoll.c @@ -0,0 +1,59 @@ +/**************************************************************************** + * libc/string/lib_strcoll.c + * + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 + +#ifdef CONFIG_LIBC_LOCALE + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strcoll + * + * Description: + * The strcoll() compares the string pointed to by a to the string pointed + * to by b, using an interpretation appropriate to the current + * LC_COLLATE state. Current implementation doesn't care about locale. + * + ****************************************************************************/ + +int strcoll(const char *a, const char *b) +{ + return strcmp(a, b); +} +#endif diff --git a/libc/string/lib_strxfrm.c b/libc/string/lib_strxfrm.c new file mode 100644 index 00000000000..61b6bba7e71 --- /dev/null +++ b/libc/string/lib_strxfrm.c @@ -0,0 +1,80 @@ +/**************************************************************************** + * libc/string/lib_strxfrm.c + * + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 + +#ifdef CONFIG_LIBC_LOCALE + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: strxfrm + * + * Description: + * This function transforms the string pointed to by s2 and places the + * resulting string into the array pointed to by s1. The transformation is + * such that if the strcmp() function is applied to the two transformed + * strings, it returns a value greater than, equal to, or less than zero, + * correspoinding to the result of a <> function applied to the + * same two original strings. + * With a C locale, this function just copies. + * + ****************************************************************************/ + +size_t strxfrm(FAR char *s1, FAR const char *s2, size_t n) +{ + size_t res; + res = 0; + while (n-- > 0) + { + if ((*s1++ = *s2++) != '\0') + { + ++res; + } + else + { + return res; + } + } + while (*s2) + { + ++s2; + ++res; + } + + return res; +} +#endif diff --git a/libc/wchar/Make.defs b/libc/wchar/Make.defs index 45936e895b0..4ec911e7b98 100644 --- a/libc/wchar/Make.defs +++ b/libc/wchar/Make.defs @@ -1,7 +1,7 @@ ############################################################################ # libc/wchar/Make.defs # -# Copyright (C) 2011-2012, 2014, 2016 Gregory Nutt. All rights reserved. +# Copyright (C) 2016 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -33,13 +33,19 @@ # ############################################################################ +ifeq ($(CONFIG_LIBC_WCHAR),y) + # Add the internal C files to the build CSRCS += lib_wcscmp.c lib_wcslen.c lib_wmemchr.c lib_wmemcmp.c lib_wmemcpy.c CSRCS += lib_wmemmove.c lib_wmemset.c lib_mbtowc.c lib_btowc.c lib_mbrtowc.c +CSRCS += lib_wctomb.c lib_wctob.c lib_wcslcpy.c lib_wcsxfrm.c lib_wctype.c +CSRCS += lib_wcrtomb.c # Add the wchar directory to the build DEPPATH += --dep-path wchar VPATH += :wchar +endif + diff --git a/libc/wchar/lib_btowc.c b/libc/wchar/lib_btowc.c index 73142946997..066ed654ccb 100644 --- a/libc/wchar/lib_btowc.c +++ b/libc/wchar/lib_btowc.c @@ -38,6 +38,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,7 +52,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR wint_t btowc(int c) { int retval = 0; diff --git a/libc/wchar/lib_mbrtowc.c b/libc/wchar/lib_mbrtowc.c index 09887b77e0d..a1f3ee765cd 100644 --- a/libc/wchar/lib_mbrtowc.c +++ b/libc/wchar/lib_mbrtowc.c @@ -39,6 +39,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -51,7 +53,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR size_t mbrtowc(FAR wchar_t *pwc, FAR const char *s, size_t n, mbstate_t *ps) { int retval = 0; diff --git a/libc/wchar/lib_mbtowc.c b/libc/wchar/lib_mbtowc.c index 5e50d86b28d..aba6d55b56c 100644 --- a/libc/wchar/lib_mbtowc.c +++ b/libc/wchar/lib_mbtowc.c @@ -36,6 +36,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -48,7 +50,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR int mbtowc(FAR wchar_t * pwc, FAR const char *s, size_t n) { if (s == NULL) diff --git a/libc/wchar/lib_wcrtomb.c b/libc/wchar/lib_wcrtomb.c new file mode 100644 index 00000000000..3e130da6fe1 --- /dev/null +++ b/libc/wchar/lib_wcrtomb.c @@ -0,0 +1,81 @@ +/**************************************************************************** + * libc/wchar/lib_wcrtomb.c + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 of the University 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 REGENTS 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 REGENTS 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 +#include +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: wcrtomb + * + * Description: + * Convert a wide character to a multibyte sequence + * + ****************************************************************************/ + +size_t wcrtomb(FAR char *s, wchar_t wc, FAR mbstate_t * ps) +{ + int retval = 0; + char buf[10]; + + if (s == NULL) + { + retval = wctomb((char *)buf, L'\0'); + } + else + { + retval = wctomb(s, wc); + } + + if (retval == -1) + { + return (size_t) (-1); + } + else + { + return (size_t) retval; + } +} +#endif diff --git a/libc/wchar/lib_wcscmp.c b/libc/wchar/lib_wcscmp.c index 72e6bb3565d..c16aa4362cf 100644 --- a/libc/wchar/lib_wcscmp.c +++ b/libc/wchar/lib_wcscmp.c @@ -38,6 +38,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -54,7 +56,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR int wcscmp(FAR const wchar_t *s1, FAR const wchar_t *s2) { while (*s1 == *s2++) diff --git a/libc/wchar/lib_wcscoll.c b/libc/wchar/lib_wcscoll.c index 9bdc727d212..54308a71176 100644 --- a/libc/wchar/lib_wcscoll.c +++ b/libc/wchar/lib_wcscoll.c @@ -38,6 +38,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -55,7 +57,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR int wcscoll(FAR const wchar_t *a, FAR const wchar_t *b) { return wcscmp(a, b); diff --git a/libc/wchar/lib_wcslcpy.c b/libc/wchar/lib_wcslcpy.c new file mode 100644 index 00000000000..3f0522f5048 --- /dev/null +++ b/libc/wchar/lib_wcslcpy.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * libc/wchar/lib_wcslcpy.c + * + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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 + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: wcslen + * + * Description: + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns wcslen(src); if retval >= siz, truncation occurred. + * + ****************************************************************************/ + +size_t wcslcpy(FAR wchar_t *dst, FAR const wchar_t *src, size_t siz) +{ + FAR wchar_t *d = dst; + FAR const wchar_t *s = src; + size_t n = siz; + + /* Copy as many bytes as will fit */ + + if (n != 0 && --n != 0) + { + do + { + if ((*d++ = *s++) == 0) + { + break; + } + } + while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + + if (n == 0) + { + if (siz != 0) + { + *d = '\0'; /* NUL-terminate dst */ + } + while (*s++); + } + + return (s - src - 1); /* count does not include NUL */ +} +#endif diff --git a/libc/wchar/lib_wcslen.c b/libc/wchar/lib_wcslen.c index f5a4d18afc6..2a9a8adca78 100644 --- a/libc/wchar/lib_wcslen.c +++ b/libc/wchar/lib_wcslen.c @@ -38,6 +38,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -52,7 +54,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR size_t wcslen(FAR const wchar_t *s) { FAR const wchar_t *p; diff --git a/libc/wchar/lib_wcsxfrm.c b/libc/wchar/lib_wcsxfrm.c new file mode 100644 index 00000000000..2ecad451394 --- /dev/null +++ b/libc/wchar/lib_wcsxfrm.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * libc/wchar/lib_wcsxfrm.c + * + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: wcsxfrm + * + * Description: + * The wcsxfrm() transforms the wide-character string pointed to by b to the + * wide-character string pointed to by a, comparing two transformed wide + * strings with wcscmp() should return the same result as comparing the + * original strings with wcscoll(). + * No more than n wide characters are transformed, including the trailing + * null character. The current implementation of wcsxfrm() simply uses + * wcslcpy() and does not support any language-specific transformations. + * + ****************************************************************************/ + +size_t wcsxfrm(FAR wchar_t *a, FAR const wchar_t *b, size_t n) +{ + return wcslcpy(a, b, n); +} +#endif diff --git a/libc/wchar/lib_wctob.c b/libc/wchar/lib_wctob.c new file mode 100644 index 00000000000..75290974e07 --- /dev/null +++ b/libc/wchar/lib_wctob.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * libc/wchar/lib_wctob.c + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 of the University 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 REGENTS 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 REGENTS 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 +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef MB_LEN_MAX +# define MB_LEN_MAX 8 +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int wctob(wint_t wc) +{ + unsigned char pmb[MB_LEN_MAX]; + + if (wc == WEOF) + { + return EOF; + } + + return wctomb((char *)pmb, wc) == 1 ? (int)pmb[0] : EOF; +} +#endif diff --git a/libc/wchar/lib_wctomb.c b/libc/wchar/lib_wctomb.c new file mode 100644 index 00000000000..0e865760638 --- /dev/null +++ b/libc/wchar/lib_wctomb.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * libc/wchar/lib_wctomb.c + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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 of the University 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 REGENTS 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 REGENTS 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 +#include +#include + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: wctomb + * + * Description: + * Try to represent a wide character as a multi byte + * + ****************************************************************************/ + +int wctomb(FAR char *s, wchar_t wc) +{ + if (s == NULL) + { + return 0; + } + + /* Verify that wchar is a valid single-byte character. */ + + if ((size_t) wc >= 0x100) + { + errno = EILSEQ; + return -1; + } + + *s = (char)wc; + return 1; +} +#endif diff --git a/libc/wchar/lib_wctype.c b/libc/wchar/lib_wctype.c new file mode 100644 index 00000000000..5b701c7cf6f --- /dev/null +++ b/libc/wchar/lib_wctype.c @@ -0,0 +1,143 @@ +/**************************************************************************** + * libc/wchar/wctype.c + * + * Copyright (c) 2002 Red Hat Incorporated. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 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. + * + * The name of Red Hat Incorporated may not 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 RED HAT INCORPORATED 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 + +#ifdef CONFIG_LIBC_WCHAR + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +wctype_t wctype(FAR const char *c) +{ + switch (*c) + { + case 'a': + if (!strcmp(c, "alnum")) + { + return WC_ALNUM; + } + else if (!strcmp(c, "alpha")) + { + return WC_ALPHA; + } + + break; + + case 'b': + if (!strcmp(c, "blank")) + { + return WC_BLANK; + } + + break; + + case 'c': + if (!strcmp(c, "cntrl")) + { + return WC_CNTRL; + } + + break; + + case 'd': + if (!strcmp(c, "digit")) + { + return WC_DIGIT; + } + + break; + + case 'g': + if (!strcmp(c, "graph")) + { + return WC_GRAPH; + } + + break; + + case 'l': + if (!strcmp(c, "lower")) + { + return WC_LOWER; + } + + break; + + case 'p': + if (!strcmp(c, "print")) + { + return WC_PRINT; + } + else if (!strcmp(c, "punct")) + { + return WC_PUNCT; + } + + break; + + case 's': + if (!strcmp(c, "space")) + { + return WC_SPACE; + } + + break; + + case 'u': + if (!strcmp(c, "upper")) + { + return WC_UPPER; + } + + break; + + case 'x': + if (!strcmp(c, "xdigit")) + { + return WC_XDIGIT; + } + + break; + } + + return 0; +} +#endif diff --git a/libc/wchar/lib_wmemchr.c b/libc/wchar/lib_wmemchr.c index 732c4ca019a..4f3e6073cba 100644 --- a/libc/wchar/lib_wmemchr.c +++ b/libc/wchar/lib_wmemchr.c @@ -36,6 +36,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,7 +52,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR FAR wchar_t *wmemchr(FAR wchar_t *s, wchar_t c, size_t n) { size_t i; diff --git a/libc/wchar/lib_wmemcmp.c b/libc/wchar/lib_wmemcmp.c index 134f69e0d1c..05b473a09c7 100644 --- a/libc/wchar/lib_wmemcmp.c +++ b/libc/wchar/lib_wmemcmp.c @@ -36,6 +36,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,7 +52,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR int wmemcmp(FAR const wchar_t *s1, FAR const wchar_t *s2, size_t n) { size_t i; diff --git a/libc/wchar/lib_wmemcpy.c b/libc/wchar/lib_wmemcpy.c index 8a28173c7f5..8441ae70b2d 100644 --- a/libc/wchar/lib_wmemcpy.c +++ b/libc/wchar/lib_wmemcpy.c @@ -36,6 +36,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,7 +52,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR FAR wchar_t *wmemcpy(FAR wchar_t *d, FAR wchar_t *s, size_t n) { return (FAR wchar_t *) memcpy(d, s, n * sizeof(wchar_t)); diff --git a/libc/wchar/lib_wmemmove.c b/libc/wchar/lib_wmemmove.c index 3ce34272f32..cbe986ab07a 100644 --- a/libc/wchar/lib_wmemmove.c +++ b/libc/wchar/lib_wmemmove.c @@ -36,6 +36,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,7 +52,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR FAR wchar_t *wmemmove(FAR wchar_t *d, FAR const wchar_t *s, size_t n) { return (FAR wchar_t *) memmove(d, s, n * sizeof(wchar_t)); diff --git a/libc/wchar/lib_wmemset.c b/libc/wchar/lib_wmemset.c index 8eea8a23edc..55da0895012 100644 --- a/libc/wchar/lib_wmemset.c +++ b/libc/wchar/lib_wmemset.c @@ -36,6 +36,8 @@ #include #include +#ifdef CONFIG_LIBC_WCHAR + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -50,7 +52,6 @@ * ****************************************************************************/ -#ifdef CONFIG_LIBC_WCHAR FAR wchar_t *wmemset(FAR wchar_t *s, wchar_t c, size_t n) { FAR wchar_t *p;