FreeBSD/Linux Kernel Cross Reference
sys/netsmb/iconv.c
1 /* $NetBSD: iconv.c,v 1.12 2006/11/16 01:33:51 christos Exp $ */
2
3 /* Public domain */
4
5 #include <sys/cdefs.h>
6 __KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.12 2006/11/16 01:33:51 christos 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,
18 void **handle)
19 {
20 return 0;
21 }
22
23 int
24 iconv_close(void *handle)
25 {
26 return 0;
27 }
28
29 int
30 iconv_conv(void *handle, const char **inbuf,
31 size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
32 {
33 if (*inbytesleft > *outbytesleft)
34 return(E2BIG);
35
36 if (inbuf == NULL)
37 return(0); /* initial shift state */
38
39 (void)memcpy(*outbuf, *inbuf, *inbytesleft);
40
41 *outbytesleft -= *inbytesleft;
42
43 *inbuf += *inbytesleft;
44 *outbuf += *inbytesleft;
45
46 *inbytesleft = 0;
47
48 return 0;
49 }
50
51 char *
52 iconv_convstr(void *handle, char *dst, const char *src, size_t l)
53 {
54 char *p = dst;
55 size_t inlen, outlen;
56 int error;
57
58 if (handle == NULL) {
59 strlcpy(dst, src, l);
60 return dst;
61 }
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;
71 }
72
73 void *
74 iconv_convmem(void *handle, void *dst, const void *src, int size)
75 {
76 const char *s = src;
77 char *d = dst;
78 size_t inlen, outlen;
79 int error;
80
81 if (size == 0)
82 return dst;
83 if (handle == NULL) {
84 memcpy(dst, src, size);
85 return dst;
86 }
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;
95 }
96
97 int
98 iconv_lookupcp(const char **cpp, const char *s)
99 {
100 for (; *cpp; cpp++)
101 if (strcmp(*cpp, s) == 0)
102 return 0;
103 return ENOENT;
104 }
Cache object: 1e08e502d6d9bc0e8c8f5e40c83792a5
|