Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / nvi / common / util2.c
blob561b1a7c2a6c6226d7be1def3a27b3b23d278825
1 /* $NetBSD$ */
3 #include "config.h"
5 #include <sys/types.h>
6 #include <sys/queue.h>
7 #include <sys/time.h>
9 #include <bitstring.h>
10 #include <errno.h>
11 #include <limits.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <unistd.h>
17 #include "multibyte.h"
19 int
20 ucs2utf8(const CHAR_T *src, size_t len, char *dst)
22 int i, j;
24 for (i = 0, j = 0; i < len; ++i) {
25 if (src[i] < 0x80)
26 dst[j++] = src[i];
27 else if (src[i] < 0x800) {
28 dst[j++] = (src[i] >> 6) | 0xc0;
29 dst[j++] = (src[i] & 0x3f) | 0x80;
30 } else {
31 dst[j++] = (src[i] >> 12) | 0xe0;
32 dst[j++] = ((src[i] >> 6) & 0x3f) | 0x80;
33 dst[j++] = (src[i] & 0x3f) | 0x80;
37 return j;