utf8.c revision 04bdb234571448ed6194e1d4048e6512f2446f1c
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Huntstatic char *rcsid = "$Id: utf8.c,v 1.12 2000/10/25 06:43:00 ishisone Exp $";
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * Copyright (c) 2000 Japan Network Information Center. All rights reserved.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * By using this file, you agree to the terms and conditions set forth bellow.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * LICENSE TERMS AND CONDITIONS
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * The following License Terms and Conditions apply, unless a different
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * license is obtained from Japan Network Information Center ("JPNIC"),
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * a Japanese association, Fuundo Bldg., 1-2 Kanda Ogawamachi, Chiyoda-ku,
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * Tokyo, Japan.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * 1. Use, Modification and Redistribution (including distribution of any
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * modified or derived work) in source and/or binary forms is permitted
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * under this License Terms and Conditions.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * 2. Redistribution of source code must retain the copyright notices as they
9f5443280fcfd625a06f63a1b457ed2335840278Mark Andrews * appear in each source code file, this License Terms and Conditions.
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * 3. Redistribution in binary form must reproduce the Copyright Notice,
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * this License Terms and Conditions, in the documentation and/or other
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * materials provided with the distribution. For the purposes of binary
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * distribution the "Copyright Notice" refers to the following language:
f6096b958c8b58c4709860d7c4dcdde5deeacb7aEvan Hunt * "Copyright (c) Japan Network Information Center. All rights reserved."
* 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
#include <config.h>
#include <stddef.h>
#define UTF8_WIDTH(c) \
mdn_utf8_mblen(const char *s) {
return UTF8_WIDTH(c);
unsigned char *q = (unsigned char *)buf;
w = width;
if (!VALID_CONT_BYTE(*p))
return (width);
unsigned long min;
int width;
int rest;
switch (width) {
min = 0;
while (rest-- > 0) {
if (!VALID_CONT_BYTE(*p))
if (v < min)
*vp = v;
return (width);
int mask;
int off;
mask = 0;
if (len < l)
while (off > 0) {
mdn_utf8_isvalidchar(const char *s) {
unsigned long dummy;
mdn_utf8_isvalidstring(const char *s) {
unsigned long dummy;
int width;
if (width == 0)
s += width;
const unsigned char *t = (const unsigned char *)known_top;
if (!VALID_CONT_BYTE(*p))
if (p < t || UTF8_WIDTH(*p) == 0)
return (NULL);