Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / distrib / utils / libhack / multibyte.c
blobfdcd9881cbd7c5ec9dfa4877ffa191b8d3886896
1 /* $NetBSD: multibyte.c,v 1.3 2008/07/12 19:20:03 dsl Exp $ */
3 /*
4 * Ignore all multibyte sequences, removes all the citrus code.
5 * Probably only used by vfprintf() when parsing the format string.
6 * And possibly from libcurses if compiled with HAVE_WCHAR.
7 */
9 #include <wchar.h>
11 size_t
12 mbrtowc(wchar_t *wc, const char *str, size_t max_sz, mbstate_t *ps)
14 return str == NULL || (*wc = (unsigned char)*str) == 0 ? 0 : 1;
17 size_t
18 wcrtomb(char *str, wchar_t wc, mbstate_t *ps)
20 *str = wc & 0xFF;
21 return 1;
24 int
25 wctob(wint_t x)
27 return x;
30 wint_t
31 btowc(int x) {
32 return x;
35 size_t
36 mbrlen(const char * __restrict p, size_t l, mbstate_t * __restrict v)
38 size_t i;
39 for (i = 0; i < l; i++)
40 if (p[i] == '\0')
41 return i;
42 return l;
45 int
46 mbsinit(const mbstate_t *s)
48 return 0;
51 size_t
52 mbsrtowcs(wchar_t * __restrict pwcs, const char ** __restrict s, size_t n,
53 mbstate_t * __restrict ps)
55 const char *p;
56 wchar_t *d;
57 size_t count;
59 for (p = *s, d = pwcs, count = 0;
60 count <= n;
61 count++, d++, p++)
63 if (mbrtowc(d, p, 1, ps) == 0)
64 break;
66 return count;
69 size_t
70 wcsrtombs(char * __restrict s, const wchar_t ** __restrict pwcs, size_t n,
71 mbstate_t * __restrict ps)
73 char *d;
74 const wchar_t *p;
75 size_t count;
77 for (p = *pwcs, d = s, count = 0;
78 count <= n && *p != 0;
79 count++, d++, p++)
81 wcrtomb(d, *p, ps);
83 *d = 0;
84 return count;