iconv.h revision 255297
1219019Sgabor/*	$FreeBSD: head/include/iconv.h 255297 2013-09-06 09:46:44Z theraven $	*/
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 <wchar.h>
39219019Sgabor
40219019Sgabor#include <sys/cdefs.h>
41219019Sgabor#include <sys/types.h>
42219019Sgabor
43254273Speter#include <_libiconv_compat.h>
44254273Speter#ifdef __LIBICONV_COMPAT
45254273Speter#define libiconv_open		iconv_open
46254273Speter#define libiconv_close		iconv_close
47254273Speter#define libiconv		iconv
48254273Speter#define libiconv_t		iconv_t
49254273Speter#endif
50255297Stheraven#ifdef __cplusplus
51255297Stheraventypedef	bool	__iconv_bool;
52255297Stheraven#elif __STDC_VERSION__ >= 199901L
53255297Stheraventypedef	_Bool	__iconv_bool;
54255297Stheraven#else
55255297Stheraventypedef	int	__iconv_bool;
56255297Stheraven#endif
57219019Sgabor
58219019Sgaborstruct __tag_iconv_t;
59219019Sgabortypedef	struct __tag_iconv_t	*iconv_t;
60219019Sgabor
61219019Sgabor__BEGIN_DECLS
62254273Spetericonv_t	iconv_open(const char *, const char *);
63254273Spetersize_t	iconv(iconv_t, const char ** __restrict,
64254273Speter	      size_t * __restrict, char ** __restrict,
65254273Speter	      size_t * __restrict);
66254273Speterint	iconv_close(iconv_t);
67219019Sgabor/*
68219019Sgabor * non-portable interfaces for iconv
69219019Sgabor */
70255297Stheravenint	__iconv_get_list(char ***, size_t *, __iconv_bool);
71219019Sgaborvoid	__iconv_free_list(char **, size_t);
72252547Spetersize_t	__iconv(iconv_t, const char **, size_t *, char **,
73219019Sgabor		     size_t *, __uint32_t, size_t *);
74219019Sgabor#define __ICONV_F_HIDE_INVALID	0x0001
75219019Sgabor
76219019Sgabor/*
77219019Sgabor * GNU interfaces for iconv
78219019Sgabor */
79254273Speter#ifdef __LIBICONV_COMPAT
80254273Speter#define libiconv_open_into		iconv_open_into
81254273Speter#define libiconvctl			iconvctl
82254273Speter#define libiconvlist			iconvlist
83254273Speter#define libiconv_set_relocation_prefix	iconv_set_relocation_prefix
84254273Speter#endif
85219019Sgabor
86219019Sgabor/* We have iconvctl() */
87254273Speter#define _ICONV_VERSION	0x0108
88254273Speterextern int _iconv_version;
89219019Sgabor
90254273Speter#ifdef __LIBICONV_COMPAT
91254273Speter#define _libiconv_version		_iconv_version
92254273Speter#define _LIBICONV_VERSION		_ICONV_VERSION
93254273Speter#endif
94254273Speter
95219019Sgabortypedef struct {
96219019Sgabor	void	*spaceholder[64];
97219019Sgabor} iconv_allocation_t;
98219019Sgabor
99219019Sgaborint	 iconv_open_into(const char *, const char *, iconv_allocation_t *);
100254273Spetervoid	 iconv_set_relocation_prefix(const char *orig_prefix,
101219019Sgabor	     const char *curr_prefix);
102219019Sgabor
103219019Sgabor/*
104219019Sgabor * iconvctl() request macros
105219019Sgabor */
106219019Sgabor#define ICONV_TRIVIALP		0
107219019Sgabor#define	ICONV_GET_TRANSLITERATE	1
108219019Sgabor#define	ICONV_SET_TRANSLITERATE	2
109219019Sgabor#define ICONV_GET_DISCARD_ILSEQ	3
110219019Sgabor#define ICONV_SET_DISCARD_ILSEQ	4
111219019Sgabor#define ICONV_SET_HOOKS		5
112219019Sgabor#define ICONV_SET_FALLBACKS	6
113219019Sgabor
114219019Sgabortypedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data);
115219019Sgabortypedef void (*iconv_wide_char_hook) (wchar_t wc, void *data);
116219019Sgabor
117219019Sgaborstruct iconv_hooks {
118219019Sgabor	iconv_unicode_char_hook		 uc_hook;
119219019Sgabor	iconv_wide_char_hook		 wc_hook;
120219019Sgabor	void				*data;
121219019Sgabor};
122219019Sgabor
123219019Sgabor/*
124219019Sgabor * Fallbacks aren't supported but type definitions are provided for
125219019Sgabor * source compatibility.
126219019Sgabor */
127219019Sgabortypedef void (*iconv_unicode_mb_to_uc_fallback) (const char*,
128219019Sgabor		size_t, void (*write_replacement) (const unsigned int *,
129219019Sgabor		size_t, void*),	void*, void*);
130219019Sgabortypedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int,
131219019Sgabor		void (*write_replacement) (const char *, size_t, void*),
132219019Sgabor		void*, void*);
133219019Sgabortypedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t,
134219019Sgabor		void (*write_replacement) (const wchar_t *, size_t, void*),
135219019Sgabor		void*, void*);
136219019Sgabortypedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t,
137219019Sgabor		void (*write_replacement) (const char *, size_t, void*),
138219019Sgabor		void*, void*);
139219019Sgabor
140219019Sgaborstruct iconv_fallbacks {
141219019Sgabor	iconv_unicode_mb_to_uc_fallback	 mb_to_uc_fallback;
142219019Sgabor	iconv_unicode_uc_to_mb_fallback  uc_to_mb_fallback;
143219019Sgabor	iconv_wchar_mb_to_wc_fallback	 mb_to_wc_fallback;
144219019Sgabor	iconv_wchar_wc_to_mb_fallback	 wc_to_mb_fallback;
145219019Sgabor	void				*data;
146219019Sgabor};
147219019Sgabor
148219019Sgabor
149219019Sgaborvoid		 iconvlist(int (*do_one) (unsigned int, const char * const *,
150219019Sgabor		    void *), void *);
151219019Sgaborconst char	*iconv_canonicalize(const char *);
152219019Sgaborint		 iconvctl(iconv_t, int, void *);
153219019Sgabor__END_DECLS
154219019Sgabor
155219019Sgabor#endif /* !_ICONV_H_ */
156