2 * Copyright (c) 2000-2001, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $FreeBSD: src/sys/sys/iconv.h,v 1.1.2.1 2001/05/21 08:28:07 bp Exp $
33 * $DragonFly: src/sys/sys/iconv.h,v 1.2 2003/06/17 04:28:58 dillon Exp $
38 #define ICONV_CSNMAXLEN 31 /* maximum length of charset name */
39 #define ICONV_CNVNMAXLEN 31 /* maximum length of converter name */
40 #define ICONV_CSMAXDATALEN 1024 /* maximum size of data associated with cs pair */
43 * Entry for cslist sysctl
45 #define ICONV_CSPAIR_INFO_VER 1
47 struct iconv_cspair_info {
52 char cs_to[ICONV_CSNMAXLEN];
53 char cs_from[ICONV_CSNMAXLEN];
57 * Paramters for 'add' sysctl
59 #define ICONV_ADD_VER 1
63 char ia_converter[ICONV_CNVNMAXLEN];
64 char ia_to[ICONV_CSNMAXLEN];
65 char ia_from[ICONV_CSNMAXLEN];
70 struct iconv_add_out {
78 int kiconv_add_xlat_table(const char *, const char *, const u_char *);
85 #include <sys/queue.h> /* can't avoid that */
86 #include <sys/sysctl.h> /* can't avoid that */
89 struct iconv_cspairdata;
92 * iconv converter class definition
94 struct iconv_converter_class {
96 TAILQ_ENTRY(iconv_converter_class) cc_link;
100 int cp_id; /* unique id of charset pair */
101 int cp_refcount; /* number of references from other pairs */
102 const char * cp_from;
105 struct iconv_converter_class * cp_dcp;
106 struct iconv_cspair *cp_base;
107 TAILQ_ENTRY(iconv_cspair) cp_link;
110 #define KICONV_CONVERTER(name,size) \
111 static DEFINE_CLASS(iconv_ ## name, iconv_ ## name ## _methods, (size)); \
112 static moduledata_t iconv_ ## name ## _mod = { \
113 "iconv_"#name, iconv_converter_handler, \
114 (void*)&iconv_ ## name ## _class \
116 DECLARE_MODULE(iconv_ ## name, iconv_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
118 #define KICONV_CES(name,size) \
119 static DEFINE_CLASS(iconv_ces_ ## name, iconv_ces_ ## name ## _methods, (size)); \
120 static moduledata_t iconv_ces_ ## name ## _mod = { \
121 "iconv_ces_"#name, iconv_cesmod_handler, \
122 (void*)&iconv_ces_ ## name ## _class \
124 DECLARE_MODULE(iconv_ces_ ## name, iconv_ces_ ## name ## _mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
126 #ifdef MALLOC_DECLARE
127 MALLOC_DECLARE(M_ICONV);
131 * Basic conversion functions
133 int iconv_open(const char *to, const char *from, void **handle);
134 int iconv_close(void *handle);
135 int iconv_conv(void *handle, const char **inbuf,
136 size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
137 char* iconv_convstr(void *handle, char *dst, const char *src);
138 void* iconv_convmem(void *handle, void *dst, const void *src, int size);
143 int iconv_lookupcp(char **cpp, const char *s);
145 int iconv_converter_initstub(struct iconv_converter_class *dp);
146 int iconv_converter_donestub(struct iconv_converter_class *dp);
147 int iconv_converter_handler(module_t mod, int type, void *data);
150 #define ICDEBUG(format, args...) printf("%s: "format, __FUNCTION__ ,## args)
152 #define ICDEBUG(format, args...)
155 #endif /* !_KERNEL */
157 #endif /* !_SYS_ICONV_H_ */