align CHAR_T string in log
[nvi.git] / common / util2.c
blob7f98825b74bfe9b8a8654d08ad84e6c2aed71f0a
1 #include "config.h"
3 #include <sys/types.h>
4 #include <sys/queue.h>
5 #include <sys/time.h>
7 #include <bitstring.h>
8 #include <errno.h>
9 #include <limits.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <unistd.h>
15 #include "multibyte.h"
18 * PUBLIC: void * v_strset __P((CHAR_T *s, CHAR_T c, size_t n));
20 void *
21 v_strset(CHAR_T *s, CHAR_T c, size_t n)
23 CHAR_T *ss = s;
25 while (n--) *s++ = c;
26 return ss;
29 int
30 ucs2utf8(const CHAR_T *src, size_t len, char *dst)
32 int i, j;
34 for (i = 0, j = 0; i < len; ++i) {
35 if (src[i] < 0x80)
36 dst[j++] = src[i];
37 else if (src[i] < 0x800) {
38 dst[j++] = (src[i] >> 6) | 0xc0;
39 dst[j++] = (src[i] & 0x3f) | 0x80;
40 } else {
41 dst[j++] = (src[i] >> 12) | 0xe0;
42 dst[j++] = ((src[i] >> 6) & 0x3f) | 0x80;
43 dst[j++] = (src[i] & 0x3f) | 0x80;
47 return j;