xref: /freebsd/lib/libkiconv/xlat16_sysctl.c (revision 294246bb7db1fb65230d917c401271c4b0e7c672)
1c4f02a89SMax Khon /*
2c4f02a89SMax Khon  * Copyright (c) 2000-2001, Boris Popov
3c4f02a89SMax Khon  * All rights reserved.
4c4f02a89SMax Khon  *
5c4f02a89SMax Khon  * Redistribution and use in source and binary forms, with or without
6c4f02a89SMax Khon  * modification, are permitted provided that the following conditions
7c4f02a89SMax Khon  * are met:
8c4f02a89SMax Khon  * 1. Redistributions of source code must retain the above copyright
9c4f02a89SMax Khon  *    notice, this list of conditions and the following disclaimer.
10c4f02a89SMax Khon  * 2. Redistributions in binary form must reproduce the above copyright
11c4f02a89SMax Khon  *    notice, this list of conditions and the following disclaimer in the
12c4f02a89SMax Khon  *    documentation and/or other materials provided with the distribution.
13c4f02a89SMax Khon  * 3. All advertising materials mentioning features or use of this software
14c4f02a89SMax Khon  *    must display the following acknowledgement:
15c4f02a89SMax Khon  *    This product includes software developed by Boris Popov.
16c4f02a89SMax Khon  * 4. Neither the name of the author nor the names of any co-contributors
17c4f02a89SMax Khon  *    may be used to endorse or promote products derived from this software
18c4f02a89SMax Khon  *    without specific prior written permission.
19c4f02a89SMax Khon  *
20c4f02a89SMax Khon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21c4f02a89SMax Khon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22c4f02a89SMax Khon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23c4f02a89SMax Khon  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24c4f02a89SMax Khon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25c4f02a89SMax Khon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26c4f02a89SMax Khon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27c4f02a89SMax Khon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28c4f02a89SMax Khon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29c4f02a89SMax Khon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30c4f02a89SMax Khon  * SUCH DAMAGE.
31c4f02a89SMax Khon  *
32c4f02a89SMax Khon  * $FreeBSD$
33c4f02a89SMax Khon  */
34c4f02a89SMax Khon 
35c4f02a89SMax Khon /*
36c4f02a89SMax Khon  * kiconv(3) requires shared linked, and reduce module size
37c4f02a89SMax Khon  * when statically linked.
38c4f02a89SMax Khon  */
39c4f02a89SMax Khon 
40*294246bbSEd Maste #ifdef PIC
41c4f02a89SMax Khon 
42c4f02a89SMax Khon #include <sys/types.h>
43c4f02a89SMax Khon #include <sys/iconv.h>
44c4f02a89SMax Khon #include <sys/sysctl.h>
45c4f02a89SMax Khon 
46c4f02a89SMax Khon #include <ctype.h>
47c4f02a89SMax Khon #include <errno.h>
48c4f02a89SMax Khon #include <string.h>
49c4f02a89SMax Khon 
50c4f02a89SMax Khon int
51c4f02a89SMax Khon kiconv_add_xlat16_table(const char *to, const char *from, const void *data, int datalen)
52c4f02a89SMax Khon {
53c4f02a89SMax Khon 	struct iconv_add_in din;
54c4f02a89SMax Khon 	struct iconv_add_out dout;
55c4f02a89SMax Khon 	size_t olen;
56c4f02a89SMax Khon 
57f373a824SR. Imura 	if (strlen(from) >= ICONV_CSNMAXLEN || strlen(to) >= ICONV_CSNMAXLEN)
58c4f02a89SMax Khon 		return (EINVAL);
59c4f02a89SMax Khon 	din.ia_version = ICONV_ADD_VER;
60c4f02a89SMax Khon 	strcpy(din.ia_converter, "xlat16");
61c4f02a89SMax Khon 	strcpy(din.ia_from, from);
62c4f02a89SMax Khon 	strcpy(din.ia_to, to);
63c4f02a89SMax Khon 	din.ia_data = data;
64c4f02a89SMax Khon 	din.ia_datalen = datalen;
65c4f02a89SMax Khon 	olen = sizeof(dout);
66c4f02a89SMax Khon 	if (sysctlbyname("kern.iconv.add", &dout, &olen, &din, sizeof(din)) == -1)
67c4f02a89SMax Khon 		return (errno);
68c4f02a89SMax Khon 	return (0);
69c4f02a89SMax Khon }
70c4f02a89SMax Khon 
71c4f02a89SMax Khon #else /* statically linked */
72c4f02a89SMax Khon 
73c90c7d69SXin LI #include <sys/types.h>
74c90c7d69SXin LI #include <sys/iconv.h>
75c4f02a89SMax Khon #include <errno.h>
76c4f02a89SMax Khon 
77c4f02a89SMax Khon int
78c90c7d69SXin LI kiconv_add_xlat16_table(const char *to __unused, const char *from __unused,
79c90c7d69SXin LI     const void *data __unused, int datalen __unused)
80c4f02a89SMax Khon {
81c90c7d69SXin LI 
82c4f02a89SMax Khon 	return (EINVAL);
83c4f02a89SMax Khon }
84c4f02a89SMax Khon 
85*294246bbSEd Maste #endif /* PIC */
86