summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@nexenta.com>2010-07-30 21:32:33 -0700
committerGarrett D'Amore <garrett@nexenta.com>2010-07-30 21:32:33 -0700
commit5ffa97fa2ff163219bb606cc2bdf8bcd331ff77e (patch)
tree140001e58f965b46e23214cdda69c9b10f443045 /usr/src/lib/libc
parent7f0170614ef1f107256fe9624f57a4ea3339efbc (diff)
downloadillumos-gate-5ffa97fa2ff163219bb606cc2bdf8bcd331ff77e.tar.gz
2 We need a fully open libc (no libc_i18n) (fix build)
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r--usr/src/lib/libc/port/locale/mbftowc.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/usr/src/lib/libc/port/locale/mbftowc.c b/usr/src/lib/libc/port/locale/mbftowc.c
new file mode 100644
index 0000000000..4f5a41a994
--- /dev/null
+++ b/usr/src/lib/libc/port/locale/mbftowc.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * 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 "lint.h"
+#include <stdlib.h>
+#include <string.h>
+#include <wchar.h>
+
+/*
+ * This function is apparently referenced by parts of ON. It is
+ * not intended for public API usage -- and it is not documented.
+ *
+ * The usage appears to be to consume bytes until a character is
+ * gathered, using a supplied function. It reads exactly one
+ * character and returns the number of bytes in the multibyte string
+ * that were consumed.
+ *
+ * The string "s" is storage for the multibyte string, the
+ * wc will receive the interpreted character, the peek function
+ * obtains the next character (as an int so we can get EOF),
+ * and errorc is stuffed with the character that is responsible
+ * for a parse error, if any.
+ */
+
+int
+_mbftowc(char *s, wchar_t *wc, int (*peek)(void), int *errorc)
+{
+ int c;
+ mbstate_t mbs;
+ char *start = s;
+ int cons = 0;
+
+ for (;;) {
+ c = peek();
+ if (c < 0) {
+ /* No bytes returned? */
+ return (s - start);
+ }
+
+ *s = (char)c;
+ s++;
+
+ (void) memset(&mbs, 0, sizeof (mbs));
+ cons = mbrtowc(wc, start, s - start, &mbs);
+ if (cons >= 0) {
+ /* fully translated character */
+ return (cons);
+ }
+ if (cons == -2) {
+ /* incomplete, recycle */
+ continue;
+ }
+
+ /*
+ * Parse error, don't consider the first character part
+ * of the error.
+ */
+ s--;
+ cons = (s - start);
+ *errorc = c >= 0 ? c : 0;
+ break;
+ }
+
+ return (cons);
+}