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 * $FreeBSD$ 35c4f02a89SMax Khon */ 36c4f02a89SMax Khon 37c4f02a89SMax Khon /* 38c4f02a89SMax Khon * kiconv(3) requires shared linked, and reduce module size 39c4f02a89SMax Khon * when statically linked. 40c4f02a89SMax Khon */ 41c4f02a89SMax Khon 42294246bbSEd Maste #ifdef PIC 43c4f02a89SMax Khon 44c4f02a89SMax Khon #include <sys/types.h> 45c4f02a89SMax Khon #include <sys/iconv.h> 46c4f02a89SMax Khon #include <sys/sysctl.h> 47c4f02a89SMax Khon 48c4f02a89SMax Khon #include <ctype.h> 49c4f02a89SMax Khon #include <errno.h> 50c4f02a89SMax Khon #include <string.h> 51c4f02a89SMax Khon 52c4f02a89SMax Khon int 53c4f02a89SMax Khon kiconv_add_xlat16_table(const char *to, const char *from, const void *data, int datalen) 54c4f02a89SMax Khon { 55c4f02a89SMax Khon struct iconv_add_in din; 56c4f02a89SMax Khon struct iconv_add_out dout; 57c4f02a89SMax Khon size_t olen; 58c4f02a89SMax Khon 59f373a824SR. Imura if (strlen(from) >= ICONV_CSNMAXLEN || strlen(to) >= ICONV_CSNMAXLEN) 60c4f02a89SMax Khon return (EINVAL); 61c4f02a89SMax Khon din.ia_version = ICONV_ADD_VER; 62c4f02a89SMax Khon strcpy(din.ia_converter, "xlat16"); 63c4f02a89SMax Khon strcpy(din.ia_from, from); 64c4f02a89SMax Khon strcpy(din.ia_to, to); 65c4f02a89SMax Khon din.ia_data = data; 66c4f02a89SMax Khon din.ia_datalen = datalen; 67c4f02a89SMax Khon olen = sizeof(dout); 68c4f02a89SMax Khon if (sysctlbyname("kern.iconv.add", &dout, &olen, &din, sizeof(din)) == -1) 69c4f02a89SMax Khon return (errno); 70c4f02a89SMax Khon return (0); 71c4f02a89SMax Khon } 72c4f02a89SMax Khon 73c4f02a89SMax Khon #else /* statically linked */ 74c4f02a89SMax Khon 75c90c7d69SXin LI #include <sys/types.h> 76c90c7d69SXin LI #include <sys/iconv.h> 77c4f02a89SMax Khon #include <errno.h> 78c4f02a89SMax Khon 79c4f02a89SMax Khon int 80c90c7d69SXin LI kiconv_add_xlat16_table(const char *to __unused, const char *from __unused, 81c90c7d69SXin LI const void *data __unused, int datalen __unused) 82c4f02a89SMax Khon { 83c90c7d69SXin LI 84c4f02a89SMax Khon return (EINVAL); 85c4f02a89SMax Khon } 86c4f02a89SMax Khon 87294246bbSEd Maste #endif /* PIC */ 88