1*df57947fSPedro F. Giffuni /*-
2*df57947fSPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
3*df57947fSPedro F. Giffuni *
4c4f02a89SMax Khon * Copyright (c) 2000-2001, Boris Popov
5c4f02a89SMax Khon * All rights reserved.
6c4f02a89SMax Khon *
7c4f02a89SMax Khon * Redistribution and use in source and binary forms, with or without
8c4f02a89SMax Khon * modification, are permitted provided that the following conditions
9c4f02a89SMax Khon * are met:
10c4f02a89SMax Khon * 1. Redistributions of source code must retain the above copyright
11c4f02a89SMax Khon * notice, this list of conditions and the following disclaimer.
12c4f02a89SMax Khon * 2. Redistributions in binary form must reproduce the above copyright
13c4f02a89SMax Khon * notice, this list of conditions and the following disclaimer in the
14c4f02a89SMax Khon * documentation and/or other materials provided with the distribution.
15c4f02a89SMax Khon * 3. All advertising materials mentioning features or use of this software
16c4f02a89SMax Khon * must display the following acknowledgement:
17c4f02a89SMax Khon * This product includes software developed by Boris Popov.
18c4f02a89SMax Khon * 4. Neither the name of the author nor the names of any co-contributors
19c4f02a89SMax Khon * may be used to endorse or promote products derived from this software
20c4f02a89SMax Khon * without specific prior written permission.
21c4f02a89SMax Khon *
22c4f02a89SMax Khon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23c4f02a89SMax Khon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24c4f02a89SMax Khon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25c4f02a89SMax Khon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26c4f02a89SMax Khon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27c4f02a89SMax Khon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28c4f02a89SMax Khon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29c4f02a89SMax Khon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30c4f02a89SMax Khon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31c4f02a89SMax Khon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32c4f02a89SMax Khon * SUCH DAMAGE.
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
40294246bbSEd 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
kiconv_add_xlat16_table(const char * to,const char * from,const void * data,int datalen)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
kiconv_add_xlat16_table(const char * to __unused,const char * from __unused,const void * data __unused,int datalen __unused)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
85294246bbSEd Maste #endif /* PIC */
86