summaryrefslogtreecommitdiff
path: root/lib/c32tob.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2020-01-01 17:01:54 +0100
committerBruno Haible <bruno@clisp.org>2020-01-01 17:01:54 +0100
commit86e05effe83d629bfcb4d798c4951781387a1bfa (patch)
treed6773c9eeaa2d2e640c3750c4cd997e5e399c19b /lib/c32tob.c
parentd325c7f69574f24587a6673fb11164d84bef89fa (diff)
downloadgnulib-86e05effe83d629bfcb4d798c4951781387a1bfa.tar.gz
c32tob: New module.
* lib/uchar.in.h (_GL_LARGE_CHAR32_T): New macro. (c32tob): New declaration. * lib/c32tob.c: New file. * m4/uchar.m4 (gl_UCHAR_MODULE_INDICATOR, gl_UCHAR_H_DEFAULTS): New macros. (gl_UCHAR_H): Require gl_UCHAR_H_DEFAULTS. * modules/uchar (Depends-on): Add snippet/c++defs. (Makefile.am): Include c++defs.h and substitute GNULIB_C32TOB in uchar.h. * modules/c32tob: New file. * tests/test-uchar.c: Verify that _GL_LARGE_CHAR32_T is correctly defined. * tests/test-uchar-c++.cc: Include signature.h. Test the signature of c32tob. * modules/uchar-c++-tests (Files): Add tests/signature.h. * doc/posix-functions/wctob.texi: Mention the new module.
Diffstat (limited to 'lib/c32tob.c')
-rw-r--r--lib/c32tob.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/c32tob.c b/lib/c32tob.c
new file mode 100644
index 0000000000..e9db7a1a98
--- /dev/null
+++ b/lib/c32tob.c
@@ -0,0 +1,37 @@
+/* Convert 32-bit wide character to unibyte character.
+ Copyright (C) 2020 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2020. */
+
+#include <config.h>
+
+/* Specification. */
+#include <uchar.h>
+
+int
+c32tob (wint_t wc)
+{
+#if _GL_LARGE_CHAR32_T
+ /* In all known encodings, unibyte characters correspond only to
+ characters in the BMP. */
+ if (wc != WEOF && (wchar_t) wc == wc)
+ return wctob ((wchar_t) wc);
+ else
+ return EOF;
+#else
+ return wctob (wc);
+#endif
+}