1ad30f8e7SGabor Kovesdan /* $NetBSD: iconv.h,v 1.6 2005/02/03 04:39:32 perry Exp $ */ 2ad30f8e7SGabor Kovesdan 3ad30f8e7SGabor Kovesdan /*- 4*e58eb3c4SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause 5*e58eb3c4SPedro F. Giffuni * 6ad30f8e7SGabor Kovesdan * Copyright (c) 2003 Citrus Project, 7ad30f8e7SGabor Kovesdan * Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org> 8ad30f8e7SGabor Kovesdan * All rights reserved. 9ad30f8e7SGabor Kovesdan * 10ad30f8e7SGabor Kovesdan * Redistribution and use in source and binary forms, with or without 11ad30f8e7SGabor Kovesdan * modification, are permitted provided that the following conditions 12ad30f8e7SGabor Kovesdan * are met: 13ad30f8e7SGabor Kovesdan * 1. Redistributions of source code must retain the above copyright 14ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer. 15ad30f8e7SGabor Kovesdan * 2. Redistributions in binary form must reproduce the above copyright 16ad30f8e7SGabor Kovesdan * notice, this list of conditions and the following disclaimer in the 17ad30f8e7SGabor Kovesdan * documentation and/or other materials provided with the distribution. 18ad30f8e7SGabor Kovesdan * 19ad30f8e7SGabor Kovesdan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20ad30f8e7SGabor Kovesdan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21ad30f8e7SGabor Kovesdan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22ad30f8e7SGabor Kovesdan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23ad30f8e7SGabor Kovesdan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24ad30f8e7SGabor Kovesdan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25ad30f8e7SGabor Kovesdan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26ad30f8e7SGabor Kovesdan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27ad30f8e7SGabor Kovesdan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28ad30f8e7SGabor Kovesdan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29ad30f8e7SGabor Kovesdan * SUCH DAMAGE. 30ad30f8e7SGabor Kovesdan * 31ad30f8e7SGabor Kovesdan */ 32ad30f8e7SGabor Kovesdan 33ad30f8e7SGabor Kovesdan #ifndef _ICONV_H_ 34ad30f8e7SGabor Kovesdan #define _ICONV_H_ 35ad30f8e7SGabor Kovesdan 36ad30f8e7SGabor Kovesdan #include <sys/types.h> 37ad30f8e7SGabor Kovesdan 38ad30f8e7SGabor Kovesdan #include <wchar.h> 39ad30f8e7SGabor Kovesdan 40ad30f8e7SGabor Kovesdan #include <sys/types.h> 41ad30f8e7SGabor Kovesdan 42b49c0d58SDavid Chisnall #ifdef __cplusplus 43b49c0d58SDavid Chisnall typedef bool __iconv_bool; 44b49c0d58SDavid Chisnall #elif __STDC_VERSION__ >= 199901L 45b49c0d58SDavid Chisnall typedef _Bool __iconv_bool; 46b49c0d58SDavid Chisnall #else 47b49c0d58SDavid Chisnall typedef int __iconv_bool; 48b49c0d58SDavid Chisnall #endif 49ad30f8e7SGabor Kovesdan 50ad30f8e7SGabor Kovesdan struct __tag_iconv_t; 51ad30f8e7SGabor Kovesdan typedef struct __tag_iconv_t *iconv_t; 52ad30f8e7SGabor Kovesdan 53ad30f8e7SGabor Kovesdan __BEGIN_DECLS 540ff204bbSPeter Wemm iconv_t iconv_open(const char *, const char *); 551243a98eSTijl Coosemans size_t iconv(iconv_t, char ** __restrict, 56ad30f8e7SGabor Kovesdan size_t * __restrict, char ** __restrict, 57ad30f8e7SGabor Kovesdan size_t * __restrict); 580ff204bbSPeter Wemm int iconv_close(iconv_t); 59ad30f8e7SGabor Kovesdan /* 60ad30f8e7SGabor Kovesdan * non-portable interfaces for iconv 61ad30f8e7SGabor Kovesdan */ 62b49c0d58SDavid Chisnall int __iconv_get_list(char ***, size_t *, __iconv_bool); 63ad30f8e7SGabor Kovesdan void __iconv_free_list(char **, size_t); 641243a98eSTijl Coosemans size_t __iconv(iconv_t, char **, size_t *, char **, 65ad30f8e7SGabor Kovesdan size_t *, __uint32_t, size_t *); 66ad30f8e7SGabor Kovesdan #define __ICONV_F_HIDE_INVALID 0x0001 67ad30f8e7SGabor Kovesdan 68ad30f8e7SGabor Kovesdan /* 69ad30f8e7SGabor Kovesdan * GNU interfaces for iconv 70ad30f8e7SGabor Kovesdan */ 71ad30f8e7SGabor Kovesdan typedef struct { 72ad30f8e7SGabor Kovesdan void *spaceholder[64]; 73ad30f8e7SGabor Kovesdan } iconv_allocation_t; 74ad30f8e7SGabor Kovesdan 75ad30f8e7SGabor Kovesdan int iconv_open_into(const char *, const char *, iconv_allocation_t *); 76091b8336SPeter Wemm void iconv_set_relocation_prefix(const char *, const char *); 77ad30f8e7SGabor Kovesdan 78ad30f8e7SGabor Kovesdan /* 79ad30f8e7SGabor Kovesdan * iconvctl() request macros 80ad30f8e7SGabor Kovesdan */ 81ad30f8e7SGabor Kovesdan #define ICONV_TRIVIALP 0 82ad30f8e7SGabor Kovesdan #define ICONV_GET_TRANSLITERATE 1 83ad30f8e7SGabor Kovesdan #define ICONV_SET_TRANSLITERATE 2 84ad30f8e7SGabor Kovesdan #define ICONV_GET_DISCARD_ILSEQ 3 85ad30f8e7SGabor Kovesdan #define ICONV_SET_DISCARD_ILSEQ 4 86ad30f8e7SGabor Kovesdan #define ICONV_SET_HOOKS 5 87ad30f8e7SGabor Kovesdan #define ICONV_SET_FALLBACKS 6 887c5b2311SHiroki Sato #define ICONV_GET_ILSEQ_INVALID 128 897c5b2311SHiroki Sato #define ICONV_SET_ILSEQ_INVALID 129 90ad30f8e7SGabor Kovesdan 91ad30f8e7SGabor Kovesdan typedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data); 92ad30f8e7SGabor Kovesdan typedef void (*iconv_wide_char_hook) (wchar_t wc, void *data); 93ad30f8e7SGabor Kovesdan 94ad30f8e7SGabor Kovesdan struct iconv_hooks { 95ad30f8e7SGabor Kovesdan iconv_unicode_char_hook uc_hook; 96ad30f8e7SGabor Kovesdan iconv_wide_char_hook wc_hook; 97ad30f8e7SGabor Kovesdan void *data; 98ad30f8e7SGabor Kovesdan }; 99ad30f8e7SGabor Kovesdan 100ad30f8e7SGabor Kovesdan /* 101ad30f8e7SGabor Kovesdan * Fallbacks aren't supported but type definitions are provided for 102ad30f8e7SGabor Kovesdan * source compatibility. 103ad30f8e7SGabor Kovesdan */ 104ad30f8e7SGabor Kovesdan typedef void (*iconv_unicode_mb_to_uc_fallback) (const char*, 105ad30f8e7SGabor Kovesdan size_t, void (*write_replacement) (const unsigned int *, 106ad30f8e7SGabor Kovesdan size_t, void*), void*, void*); 107ad30f8e7SGabor Kovesdan typedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int, 108ad30f8e7SGabor Kovesdan void (*write_replacement) (const char *, size_t, void*), 109ad30f8e7SGabor Kovesdan void*, void*); 110ad30f8e7SGabor Kovesdan typedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t, 111ad30f8e7SGabor Kovesdan void (*write_replacement) (const wchar_t *, size_t, void*), 112ad30f8e7SGabor Kovesdan void*, void*); 113ad30f8e7SGabor Kovesdan typedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t, 114ad30f8e7SGabor Kovesdan void (*write_replacement) (const char *, size_t, void*), 115ad30f8e7SGabor Kovesdan void*, void*); 116ad30f8e7SGabor Kovesdan 117ad30f8e7SGabor Kovesdan struct iconv_fallbacks { 118ad30f8e7SGabor Kovesdan iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback; 119ad30f8e7SGabor Kovesdan iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; 120ad30f8e7SGabor Kovesdan iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback; 121ad30f8e7SGabor Kovesdan iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback; 122ad30f8e7SGabor Kovesdan void *data; 123ad30f8e7SGabor Kovesdan }; 124ad30f8e7SGabor Kovesdan 125ad30f8e7SGabor Kovesdan 126ad30f8e7SGabor Kovesdan void iconvlist(int (*do_one) (unsigned int, const char * const *, 127ad30f8e7SGabor Kovesdan void *), void *); 128ad30f8e7SGabor Kovesdan const char *iconv_canonicalize(const char *); 129ad30f8e7SGabor Kovesdan int iconvctl(iconv_t, int, void *); 130ad30f8e7SGabor Kovesdan __END_DECLS 131ad30f8e7SGabor Kovesdan 132ad30f8e7SGabor Kovesdan #endif /* !_ICONV_H_ */ 133