summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-08-03 13:49:55 +0000
committertjr <tjr@FreeBSD.org>2002-08-03 13:49:55 +0000
commiteefed45007e6816b7f886d29f31a6079c800fbb7 (patch)
tree72640c311225e824b82a58cb5b8e9e18244d8f4e
parentdc1c7f31522480211a5befcad73e5d30fa62a12d (diff)
downloadFreeBSD-src-eefed45007e6816b7f886d29f31a6079c800fbb7.zip
FreeBSD-src-eefed45007e6816b7f886d29f31a6079c800fbb7.tar.gz
Add ISO C90 Amd. 1 btowc(3) and wctob(3) functions.
-rw-r--r--include/wchar.h3
-rw-r--r--lib/libc/locale/Makefile.inc6
-rw-r--r--lib/libc/locale/btowc.377
-rw-r--r--lib/libc/locale/btowc.c45
-rw-r--r--lib/libc/locale/wctob.c41
5 files changed, 170 insertions, 2 deletions
diff --git a/include/wchar.h b/include/wchar.h
index 0c174bd..bbdcae6 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -147,6 +147,9 @@ size_t wcslcpy(wchar_t *, const wchar_t *, size_t);
int wcswidth(const wchar_t *, size_t);
int wcwidth(wchar_t);
#endif
+
+int wctob(wint_t);
+wint_t btowc(int);
__END_DECLS
#endif /* !_WCHAR_H_ */
diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc
index 2d2ea34..0871fc7 100644
--- a/lib/libc/locale/Makefile.inc
+++ b/lib/libc/locale/Makefile.inc
@@ -4,14 +4,15 @@
# locale sources
.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/locale ${.CURDIR}/../libc/locale
-SRCS+= ansi.c big5.c collate.c collcmp.c euc.c fix_grouping.c frune.c \
+SRCS+= ansi.c big5.c btowc.c collate.c collcmp.c euc.c fix_grouping.c frune.c \
isctype.c \
ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \
mskanji.c nl_langinfo.c nomacros.c none.c rune.c \
runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \
- tolower.c toupper.c utf2.c wctype.c
+ tolower.c toupper.c utf2.c wctob.c wctype.c
.if ${LIB} == "c"
+MAN+= btowc.3
MAN+= ctype.3 digittoint.3 isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 \
isdigit.3 isgraph.3 islower.3 isprint.3 ispunct.3 isspace.3 \
isupper.3 isxdigit.3 mbrune.3 multibyte.3 nl_langinfo.3 rune.3 \
@@ -28,4 +29,5 @@ MLINKS+=rune.3 fgetrune.3 rune.3 fputrune.3 rune.3 fungetrune.3 \
rune.3 sputrune.3
MLINKS+=setlocale.3 localeconv.3
MLINKS+=wctype.3 iswctype.3
+MLINKS+=btowc.3 wctob.3
.endif
diff --git a/lib/libc/locale/btowc.3 b/lib/libc/locale/btowc.3
new file mode 100644
index 0000000..ce63f65
--- /dev/null
+++ b/lib/libc/locale/btowc.3
@@ -0,0 +1,77 @@
+.\" Copyright (c) 2002 Tim J. Robbins
+.\" 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.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd August 3, 2002
+.Dt BTOWC 3
+.Os
+.Sh NAME
+.Nm btowc ,
+.Nm wctob
+.Nd "convert between wide and single-byte characters"
+.Sh LIBRARY
+.Lb libc
+.Sh SYNOPSIS
+.In wchar.h
+.Ft wint_t
+.Fn btowc "int c"
+.Ft int
+.Fn wctob "wint_t c"
+.Sh DESCRIPTION
+The
+.Fn btowc
+function converts a single-byte character into a corresponding wide character.
+If the character is
+.Dv EOF
+or not valid in the initial shift state,
+.Fn btowc
+returns
+.Dv WEOF .
+.Pp
+The
+.Fn wctob
+function converts a wide character into a corresponding single-byte character.
+If the wide character is
+.Dv WEOF
+or not able to be represented as a single byte in the initial shift state,
+.Fn wctob
+returns
+.Dv WEOF .
+.Sh SEE ALSO
+.Xr multibyte 3
+.Sh STANDARDS
+The
+.Fn btowc
+and
+.Fn wctob
+functions conform to
+.St -p1003.1-2001 .
+.Sh HISTORY
+The
+.Fn btowc
+and
+.Fn wctob
+functions first appeared in
+.Fx 5.0 .
diff --git a/lib/libc/locale/btowc.c b/lib/libc/locale/btowc.c
new file mode 100644
index 0000000..585abf8
--- /dev/null
+++ b/lib/libc/locale/btowc.c
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <rune.h>
+#include <wchar.h>
+
+wint_t
+btowc(int c)
+{
+ rune_t r;
+ char cc;
+
+ if (c == EOF)
+ return (WEOF);
+ cc = (char)c;
+ if ((r = sgetrune(&cc, 1, NULL)) == _INVALID_RUNE)
+ return (WEOF);
+ return (r);
+}
diff --git a/lib/libc/locale/wctob.c b/lib/libc/locale/wctob.c
new file mode 100644
index 0000000..070ae94
--- /dev/null
+++ b/lib/libc/locale/wctob.c
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2002 Tim J. Robbins.
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <rune.h>
+#include <wchar.h>
+
+int
+wctob(wint_t c)
+{
+ char cc;
+
+ if (c == WEOF || sputrune(c, &cc, 1, NULL) != 1)
+ return (EOF);
+ return ((unsigned char)cc);
+}
OpenPOWER on IntegriCloud