Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / netsmb / iconv.c
blobd1bbcfb84a4a8659f4b77ce4ac97e9151b16f5ac
1 /* $NetBSD: iconv.c,v 1.11 2006/10/12 01:32:46 christos Exp $ */
3 /* Public domain */
5 #include <sys/cdefs.h>
6 __KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.11 2006/10/12 01:32:46 christos Exp $");
8 #include <sys/param.h>
9 #include <sys/kernel.h>
10 #include <sys/systm.h>
11 #include <sys/errno.h>
12 #include <sys/malloc.h>
14 #include <netsmb/iconv.h>
16 int
17 iconv_open(const char *to, const char *from,
18 void **handle)
20 return 0;
23 int
24 iconv_close(void *handle)
26 return 0;
29 int
30 iconv_conv(void *handle, const char **inbuf,
31 size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
33 if (*inbytesleft > *outbytesleft)
34 return(E2BIG);
36 if (inbuf == NULL)
37 return(0); /* initial shift state */
39 (void)memcpy(*outbuf, *inbuf, *inbytesleft);
41 *outbytesleft -= *inbytesleft;
43 *inbuf += *inbytesleft;
44 *outbuf += *inbytesleft;
46 *inbytesleft = 0;
48 return 0;
51 char *
52 iconv_convstr(void *handle, char *dst, const char *src, size_t l)
54 char *p = dst;
55 size_t inlen, outlen;
56 int error;
58 if (handle == NULL) {
59 strlcpy(dst, src, l);
60 return dst;
62 inlen = outlen = strlen(src);
63 error = iconv_conv(handle, NULL, NULL, &p, &outlen);
64 if (error)
65 return NULL;
66 error = iconv_conv(handle, &src, &inlen, &p, &outlen);
67 if (error)
68 return NULL;
69 *p = 0;
70 return dst;
73 void *
74 iconv_convmem(void *handle, void *dst, const void *src, int size)
76 const char *s = src;
77 char *d = dst;
78 size_t inlen, outlen;
79 int error;
81 if (size == 0)
82 return dst;
83 if (handle == NULL) {
84 memcpy(dst, src, size);
85 return dst;
87 inlen = outlen = size;
88 error = iconv_conv(handle, NULL, NULL, &d, &outlen);
89 if (error)
90 return NULL;
91 error = iconv_conv(handle, &s, &inlen, &d, &outlen);
92 if (error)
93 return NULL;
94 return dst;
97 int
98 iconv_lookupcp(const char **cpp, const char *s)
100 for (; *cpp; cpp++)
101 if (strcmp(*cpp, s) == 0)
102 return 0;
103 return ENOENT;