diff --git a/include/stdlib.h b/include/stdlib.h index 6b4498ebea3..ddfcea74a81 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -42,8 +42,10 @@ #include #include + #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -202,6 +204,13 @@ double_t strtod(FAR const char *str, FAR char **endptr); FAR char *itoa(int val, FAR char *str, int base); +/* Wide character operations */ + +#ifdef CONFIG_LIBC_WCHAR +int mbtowc(FAR wchar_t *pwc, FAR const char *s, size_t n); +int wctomb(FAR char *s, wchar_t wchar); +#endif + /* Memory Management */ FAR void *malloc(size_t); diff --git a/include/wchar.h b/include/wchar.h index 90e3d4f12ca..582cec46832 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -33,9 +33,6 @@ * ****************************************************************************/ -#ifndef __INCLUDE_WCHAR_H -#define __INCLUDE_WCHAR_H - /**************************************************************************** * Included Files ****************************************************************************/ @@ -50,6 +47,14 @@ #include #include +/* REVISIT: Moving the idempotence to this location resolves a circular + * dependency problem with stdlib.h which gets included indirectory and + * needs wchar_t. + */ + +#ifndef __INCLUDE_WCHAR_H +#define __INCLUDE_WCHAR_H + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -105,7 +110,6 @@ typedef int wint_t; * state, the results are unspecified. */ -#if 0 /* Not used */ /* Commented out because this is dangerous. This defines a type that would * be internal to some wchar implementation. NuttX does not implement the * wchar functions. Having this definition is a time bomb: If this header @@ -127,7 +131,6 @@ struct mbstate_s }; typedef struct mbstate_s mbstate_t; -#endif /* FILE * As described in . @@ -218,6 +221,8 @@ size_t wcscspn(const wchar_t *, const wchar_t *); size_t wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm *); size_t wcslen(const wchar_t *); +size_t wcslcpy(FAR wchar_t *, FAR const wchar_t *, size_t); +size_t wcslcat(FAR wchar_t *, FAR const wchar_t *, size_t); wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t); int wcsncmp(const wchar_t *, const wchar_t *, size_t); wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t); diff --git a/libc/locale/Make.defs b/libc/locale/Make.defs index bbf9c6a33db..b59b7981455 100644 --- a/libc/locale/Make.defs +++ b/libc/locale/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_LIBC_LOCALE),y) # Add the locale files to the build -CSRCS += lib_setlocale.c +CSRCS += lib_setlocale.c lib_localeconv.c # Add the locale directory to the build diff --git a/libc/locale/lib_localeconv.c b/libc/locale/lib_localeconv.c index 3238dfa10a9..697f369cf45 100644 --- a/libc/locale/lib_localeconv.c +++ b/libc/locale/lib_localeconv.c @@ -60,7 +60,7 @@ * ****************************************************************************/ -FAR struct lconv *localeconv(void); +FAR struct lconv *localeconv(void) { /* NULL indicates the the locale was not changed */ diff --git a/libc/stdlib/Make.defs b/libc/stdlib/Make.defs index 618b16a5450..22509d22dda 100644 --- a/libc/stdlib/Make.defs +++ b/libc/stdlib/Make.defs @@ -45,6 +45,10 @@ ifeq ($(CONFIG_FS_WRITABLE),y) CSRCS += lib_mktemp.c lib_mkstemp.c endif +ifeq ($(CONFIG_LIBC_WCHAR),y) +CSRCS += lib_mbtowc.c lib_wctomb.c +endif + ifeq ($(CONFIG_PSEUDOTERM_SUSV1),y) CSRCS += lib_ptsname.c lib_ptsnamer.c endif diff --git a/libc/wchar/lib_mbtowc.c b/libc/stdlib/lib_mbtowc.c similarity index 98% rename from libc/wchar/lib_mbtowc.c rename to libc/stdlib/lib_mbtowc.c index aba6d55b56c..03b2b93d4eb 100644 --- a/libc/wchar/lib_mbtowc.c +++ b/libc/stdlib/lib_mbtowc.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/wchar/lib_mbtowc.c + * libc/stdlib/lib_mbtowc.c * * Copyright (c)1999 Citrus Project, * All rights reserved. diff --git a/libc/wchar/lib_wctomb.c b/libc/stdlib/lib_wctomb.c similarity index 98% rename from libc/wchar/lib_wctomb.c rename to libc/stdlib/lib_wctomb.c index 0e865760638..cef60ad1495 100644 --- a/libc/wchar/lib_wctomb.c +++ b/libc/stdlib/lib_wctomb.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libc/wchar/lib_wctomb.c + * libc/stdlib/lib_wctomb.c * * This code is derived from software contributed to Berkeley by * Chris Torek. @@ -35,9 +35,10 @@ ****************************************************************************/ #include -#include + #include #include +#include #include #ifdef CONFIG_LIBC_WCHAR diff --git a/libc/wchar/Make.defs b/libc/wchar/Make.defs index 4ec911e7b98..f6788f592de 100644 --- a/libc/wchar/Make.defs +++ b/libc/wchar/Make.defs @@ -38,9 +38,8 @@ 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 +CSRCS += lib_wmemmove.c lib_wmemset.c lib_btowc.c lib_mbrtowc.c lib_wctob.c +CSRCS +=lib_wcslcpy.c lib_wcsxfrm.c lib_wcrtomb.c # Add the wchar directory to the build diff --git a/libc/wchar/lib_btowc.c b/libc/wchar/lib_btowc.c index 066ed654ccb..069a4dc9c4d 100644 --- a/libc/wchar/lib_btowc.c +++ b/libc/wchar/lib_btowc.c @@ -33,10 +33,11 @@ ****************************************************************************/ #include -#include + #include #include #include +#include #ifdef CONFIG_LIBC_WCHAR @@ -54,18 +55,18 @@ wint_t btowc(int c) { - int retval = 0; wchar_t pwc; - unsigned char b; + char b; + int retval = 0; if (c == EOF) { return WEOF; } - b = (unsigned char)c; + b = (char)c; - retval = mbtowc(&pwc, &b, 1); + retval = mbtowc(&pwc, (FAR const char *)&b, 1); if (retval != 0 && retval != 1) { diff --git a/libc/wchar/lib_mbrtowc.c b/libc/wchar/lib_mbrtowc.c index a1f3ee765cd..f82ff1808a1 100644 --- a/libc/wchar/lib_mbrtowc.c +++ b/libc/wchar/lib_mbrtowc.c @@ -33,11 +33,12 @@ ****************************************************************************/ #include -#include + #include #include #include #include +#include #ifdef CONFIG_LIBC_WCHAR @@ -68,11 +69,11 @@ size_t mbrtowc(FAR wchar_t *pwc, FAR const char *s, size_t n, mbstate_t *ps) if (retval == -1) { - return (size_t) (-1); + return (size_t)(-1); } else { - return (size_t) retval; + return (size_t)retval; } } #endif diff --git a/libc/wchar/lib_wcsxfrm.c b/libc/wchar/lib_wcsxfrm.c index 2ecad451394..303a540b322 100644 --- a/libc/wchar/lib_wcsxfrm.c +++ b/libc/wchar/lib_wcsxfrm.c @@ -32,6 +32,7 @@ ****************************************************************************/ #include + #include #include diff --git a/libc/wchar/lib_wctob.c b/libc/wchar/lib_wctob.c index 75290974e07..1808bf9e0da 100644 --- a/libc/wchar/lib_wctob.c +++ b/libc/wchar/lib_wctob.c @@ -35,9 +35,11 @@ ****************************************************************************/ #include -#include + #include +#include #include +#include #include #ifdef CONFIG_LIBC_WCHAR