1219019Sgabor/* $FreeBSD$ */ 2219019Sgabor/* $NetBSD: iconv.h,v 1.6 2005/02/03 04:39:32 perry Exp $ */ 3219019Sgabor 4219019Sgabor/*- 5219019Sgabor * Copyright (c) 2003 Citrus Project, 6219019Sgabor * Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org> 7219019Sgabor * All rights reserved. 8219019Sgabor * 9219019Sgabor * Redistribution and use in source and binary forms, with or without 10219019Sgabor * modification, are permitted provided that the following conditions 11219019Sgabor * are met: 12219019Sgabor * 1. Redistributions of source code must retain the above copyright 13219019Sgabor * notice, this list of conditions and the following disclaimer. 14219019Sgabor * 2. Redistributions in binary form must reproduce the above copyright 15219019Sgabor * notice, this list of conditions and the following disclaimer in the 16219019Sgabor * documentation and/or other materials provided with the distribution. 17219019Sgabor * 18219019Sgabor * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19219019Sgabor * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20219019Sgabor * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21219019Sgabor * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22219019Sgabor * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23219019Sgabor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24219019Sgabor * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25219019Sgabor * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26219019Sgabor * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27219019Sgabor * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28219019Sgabor * SUCH DAMAGE. 29219019Sgabor * 30219019Sgabor */ 31219019Sgabor 32219019Sgabor#ifndef _ICONV_H_ 33219019Sgabor#define _ICONV_H_ 34219019Sgabor 35219019Sgabor#include <sys/cdefs.h> 36219019Sgabor#include <sys/types.h> 37219019Sgabor 38219019Sgabor#include <stdbool.h> 39219019Sgabor#include <wchar.h> 40219019Sgabor 41219019Sgabor#include <sys/cdefs.h> 42219019Sgabor#include <sys/types.h> 43219019Sgabor 44219019Sgabor#define iconv_open libiconv_open 45219019Sgabor#define iconv_close libiconv_close 46219019Sgabor#define iconv(cd, in, insize, out, outsize) libiconv(cd, __DECONST(char **, in), insize, out, outsize) 47219019Sgabor#define iconv_t libiconv_t 48219019Sgabor 49219019Sgaborstruct __tag_iconv_t; 50219019Sgabortypedef struct __tag_iconv_t *iconv_t; 51219019Sgabor 52219019Sgabor__BEGIN_DECLS 53219019Sgaboriconv_t libiconv_open(const char *, const char *); 54219019Sgaborsize_t libiconv(iconv_t, char ** __restrict, 55219019Sgabor size_t * __restrict, char ** __restrict, 56219019Sgabor size_t * __restrict); 57219019Sgaborint libiconv_close(iconv_t); 58219019Sgabor/* 59219019Sgabor * non-portable interfaces for iconv 60219019Sgabor */ 61219019Sgaborint __iconv_get_list(char ***, size_t *, bool); 62219019Sgaborvoid __iconv_free_list(char **, size_t); 63219019Sgaborsize_t __iconv(iconv_t, char **, size_t *, char **, 64219019Sgabor size_t *, __uint32_t, size_t *); 65219019Sgabor#define __ICONV_F_HIDE_INVALID 0x0001 66219019Sgabor 67219019Sgabor/* 68219019Sgabor * GNU interfaces for iconv 69219019Sgabor */ 70219019Sgabor#define iconv_open_into libiconv_open_into 71219019Sgabor#define iconvctl libiconvctl 72219019Sgabor#define iconvlist libiconvlist 73219019Sgabor 74219019Sgabor/* We have iconvctl() */ 75219019Sgabor#define _LIBICONV_VERSION 0x0108 76219019Sgaborextern int _libiconv_version; 77219019Sgabor 78219019Sgabortypedef struct { 79219019Sgabor void *spaceholder[64]; 80219019Sgabor} iconv_allocation_t; 81219019Sgabor 82219019Sgaborint iconv_open_into(const char *, const char *, iconv_allocation_t *); 83219019Sgaborvoid libiconv_set_relocation_prefix (const char *orig_prefix, 84219019Sgabor const char *curr_prefix); 85219019Sgabor 86219019Sgabor/* 87219019Sgabor * iconvctl() request macros 88219019Sgabor */ 89219019Sgabor#define ICONV_TRIVIALP 0 90219019Sgabor#define ICONV_GET_TRANSLITERATE 1 91219019Sgabor#define ICONV_SET_TRANSLITERATE 2 92219019Sgabor#define ICONV_GET_DISCARD_ILSEQ 3 93219019Sgabor#define ICONV_SET_DISCARD_ILSEQ 4 94219019Sgabor#define ICONV_SET_HOOKS 5 95219019Sgabor#define ICONV_SET_FALLBACKS 6 96219019Sgabor 97219019Sgabortypedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data); 98219019Sgabortypedef void (*iconv_wide_char_hook) (wchar_t wc, void *data); 99219019Sgabor 100219019Sgaborstruct iconv_hooks { 101219019Sgabor iconv_unicode_char_hook uc_hook; 102219019Sgabor iconv_wide_char_hook wc_hook; 103219019Sgabor void *data; 104219019Sgabor}; 105219019Sgabor 106219019Sgabor/* 107219019Sgabor * Fallbacks aren't supported but type definitions are provided for 108219019Sgabor * source compatibility. 109219019Sgabor */ 110219019Sgabortypedef void (*iconv_unicode_mb_to_uc_fallback) (const char*, 111219019Sgabor size_t, void (*write_replacement) (const unsigned int *, 112219019Sgabor size_t, void*), void*, void*); 113219019Sgabortypedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int, 114219019Sgabor void (*write_replacement) (const char *, size_t, void*), 115219019Sgabor void*, void*); 116219019Sgabortypedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t, 117219019Sgabor void (*write_replacement) (const wchar_t *, size_t, void*), 118219019Sgabor void*, void*); 119219019Sgabortypedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t, 120219019Sgabor void (*write_replacement) (const char *, size_t, void*), 121219019Sgabor void*, void*); 122219019Sgabor 123219019Sgaborstruct iconv_fallbacks { 124219019Sgabor iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback; 125219019Sgabor iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; 126219019Sgabor iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback; 127219019Sgabor iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback; 128219019Sgabor void *data; 129219019Sgabor}; 130219019Sgabor 131219019Sgabor 132219019Sgaborvoid iconvlist(int (*do_one) (unsigned int, const char * const *, 133219019Sgabor void *), void *); 134219019Sgaborconst char *iconv_canonicalize(const char *); 135219019Sgaborint iconvctl(iconv_t, int, void *); 136219019Sgabor__END_DECLS 137219019Sgabor 138219019Sgabor#endif /* !_ICONV_H_ */ 139