FreeBSD/Linux Kernel Cross Reference
sys/netsmb/iconv.c
1 /* $NetBSD: iconv.c,v 1.7 2003/05/16 05:14:40 itojun Exp $ */
2
3 /* Public domain */
4
5 #include <sys/cdefs.h>
6 __KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.7 2003/05/16 05:14:40 itojun Exp $");
7
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>
13
14 #include <netsmb/iconv.h>
15
16 int
17 iconv_open(const char *to, const char *from, void **handle)
18 {
19 return 0;
20 }
21
22 int
23 iconv_close(void *handle)
24 {
25 return 0;
26 }
27
28 int
29 iconv_conv(void *handle, const char **inbuf,
30 size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
31 {
32 if (*inbytesleft > *outbytesleft)
33 return(E2BIG);
34
35 if (inbuf == NULL)
36 return(0); /* initial shift state */
37
38 memcpy((void *)*inbuf, (void *)*outbuf, *inbytesleft);
39
40 *outbytesleft -= *inbytesleft;
41
42 *inbuf += *inbytesleft;
43 *outbuf += *inbytesleft;
44
45 *inbytesleft = 0;
46
47 return 0;
48 }
49
50 char *
51 iconv_convstr(void *handle, char *dst, const char *src)
52 {
53 char *p = dst;
54 size_t inlen, outlen;
55 int error;
56
57 if (handle == NULL) {
58 strcpy(dst, src); /*XXX need to know dstlen */
59 return dst;
60 }
61 inlen = outlen = strlen(src);
62 error = iconv_conv(handle, NULL, NULL, &p, &outlen);
63 if (error)
64 return NULL;
65 error = iconv_conv(handle, &src, &inlen, &p, &outlen);
66 if (error)
67 return NULL;
68 *p = 0;
69 return dst;
70 }
71
72 void *
73 iconv_convmem(void *handle, void *dst, const void *src, int size)
74 {
75 const char *s = src;
76 char *d = dst;
77 size_t inlen, outlen;
78 int error;
79
80 if (size == 0)
81 return dst;
82 if (handle == NULL) {
83 memcpy(dst, src, size);
84 return dst;
85 }
86 inlen = outlen = size;
87 error = iconv_conv(handle, NULL, NULL, &d, &outlen);
88 if (error)
89 return NULL;
90 error = iconv_conv(handle, &s, &inlen, &d, &outlen);
91 if (error)
92 return NULL;
93 return dst;
94 }
95
96 int
97 iconv_lookupcp(const char **cpp, const char *s)
98 {
99 for (; *cpp; cpp++)
100 if (strcmp(*cpp, s) == 0)
101 return 0;
102 return ENOENT;
103 }
Cache object: 1b16cf48bc6179756679926bfea195cc
|