iconv.h revision 254273
150472Speter/*	$FreeBSD: head/include/iconv.h 254273 2013-08-13 07:15:01Z peter $	*/
237Srgrimes/*	$NetBSD: iconv.h,v 1.6 2005/02/03 04:39:32 perry Exp $	*/
337Srgrimes
437Srgrimes/*-
581020Srwatson * Copyright (c) 2003 Citrus Project,
681020Srwatson * Copyright (c) 2009, 2010 Gabor Kovesdan <gabor@FreeBSD.org>
781020Srwatson * All rights reserved.
837Srgrimes *
981020Srwatson * Redistribution and use in source and binary forms, with or without
1081020Srwatson * modification, are permitted provided that the following conditions
11116119Smarkm * are met:
12116119Smarkm * 1. Redistributions of source code must retain the above copyright
1381020Srwatson *    notice, this list of conditions and the following disclaimer.
1481020Srwatson * 2. Redistributions in binary form must reproduce the above copyright
1566621Skris *    notice, this list of conditions and the following disclaimer in the
1675017Speter *    documentation and/or other materials provided with the distribution.
1766621Skris *
1875017Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19206039Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20206039Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2181020Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2241444Sdillon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2341444Sdillon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2481020Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2581020Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2681020Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2781020Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28126863Sdes * SUCH DAMAGE.
29126863Sdes *
3018639Spst */
3118639Spst
3218639Spst#ifndef _ICONV_H_
3318639Spst#define _ICONV_H_
3418639Spst
3518639Spst#include <sys/cdefs.h>
3618639Spst#include <sys/types.h>
3775017Speter
3818639Spst#include <stdbool.h>
3975017Speter#include <wchar.h>
4018639Spst
4175017Speter#include <sys/cdefs.h>
4218639Spst#include <sys/types.h>
4375017Speter
4418639Spst#include <_libiconv_compat.h>
45116119Smarkm#ifdef __LIBICONV_COMPAT
46116119Smarkm#define libiconv_open		iconv_open
4775017Speter#define libiconv_close		iconv_close
4818639Spst#define libiconv		iconv
4975017Speter#define libiconv_t		iconv_t
5018639Spst#endif
5175017Speter
5218639Spststruct __tag_iconv_t;
5375017Spetertypedef	struct __tag_iconv_t	*iconv_t;
5418639Spst
5575017Speter__BEGIN_DECLS
5618639Spsticonv_t	iconv_open(const char *, const char *);
5755115Spetersize_t	iconv(iconv_t, const char ** __restrict,
5855115Speter	      size_t * __restrict, char ** __restrict,
5955115Speter	      size_t * __restrict);
6018639Spstint	iconv_close(iconv_t);
6155115Speter/*
6291929Sdd * non-portable interfaces for iconv
63591Srgrimes */
64101595Sgordonint	__iconv_get_list(char ***, size_t *, bool);
65831Satsvoid	__iconv_free_list(char **, size_t);
6618639Spstsize_t	__iconv(iconv_t, const char **, size_t *, char **,
6718639Spst		     size_t *, __uint32_t, size_t *);
6818639Spst#define __ICONV_F_HIDE_INVALID	0x0001
69155349Sceri
7018639Spst/*
7118639Spst * GNU interfaces for iconv
7218639Spst */
7318639Spst#ifdef __LIBICONV_COMPAT
7418639Spst#define libiconv_open_into		iconv_open_into
754652Sats#define libiconvctl			iconvctl
76831Sats#define libiconvlist			iconvlist
7721613Sache#define libiconv_set_relocation_prefix	iconv_set_relocation_prefix
7821613Sache#endif
7921613Sache
8021613Sache/* We have iconvctl() */
81115892Syar#define _ICONV_VERSION	0x0108
82115892Syarextern int _iconv_version;
83115892Syar
84115892Syar#ifdef __LIBICONV_COMPAT
8584265Skris#define _libiconv_version		_iconv_version
86115892Syar#define _LIBICONV_VERSION		_ICONV_VERSION
8784265Skris#endif
8884265Skris
8948845Ssheldonhtypedef struct {
9040911Sphk	void	*spaceholder[64];
9148845Ssheldonh} iconv_allocation_t;
9275017Speter
9340911Sphkint	 iconv_open_into(const char *, const char *, iconv_allocation_t *);
9449034Ssheldonhvoid	 iconv_set_relocation_prefix(const char *orig_prefix,
9549059Sgreen	     const char *curr_prefix);
9649059Sgreen
9718639Spst/*
9849059Sgreen * iconvctl() request macros
9975017Speter */
10029951Sjkh#define ICONV_TRIVIALP		0
10148845Ssheldonh#define	ICONV_GET_TRANSLITERATE	1
10248845Ssheldonh#define	ICONV_SET_TRANSLITERATE	2
10348846Sgreen#define ICONV_GET_DISCARD_ILSEQ	3
10448845Ssheldonh#define ICONV_SET_DISCARD_ILSEQ	4
10555779Sdbaker#define ICONV_SET_HOOKS		5
10655779Sdbaker#define ICONV_SET_FALLBACKS	6
10755779Sdbaker
10855779Sdbakertypedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data);
10937741Shoektypedef void (*iconv_wide_char_hook) (wchar_t wc, void *data);
11037741Shoek
11137741Shoekstruct iconv_hooks {
11229951Sjkh	iconv_unicode_char_hook		 uc_hook;
11384400Sjkh	iconv_wide_char_hook		 wc_hook;
11484400Sjkh	void				*data;
11529951Sjkh};
11684767Sobrien
11784767Sobrien/*
11890600Smaxim * Fallbacks aren't supported but type definitions are provided for
119 * source compatibility.
120 */
121typedef void (*iconv_unicode_mb_to_uc_fallback) (const char*,
122		size_t, void (*write_replacement) (const unsigned int *,
123		size_t, void*),	void*, void*);
124typedef void (*iconv_unicode_uc_to_mb_fallback) (unsigned int,
125		void (*write_replacement) (const char *, size_t, void*),
126		void*, void*);
127typedef void (*iconv_wchar_mb_to_wc_fallback) (const char*, size_t,
128		void (*write_replacement) (const wchar_t *, size_t, void*),
129		void*, void*);
130typedef void (*iconv_wchar_wc_to_mb_fallback) (wchar_t,
131		void (*write_replacement) (const char *, size_t, void*),
132		void*, void*);
133
134struct iconv_fallbacks {
135	iconv_unicode_mb_to_uc_fallback	 mb_to_uc_fallback;
136	iconv_unicode_uc_to_mb_fallback  uc_to_mb_fallback;
137	iconv_wchar_mb_to_wc_fallback	 mb_to_wc_fallback;
138	iconv_wchar_wc_to_mb_fallback	 wc_to_mb_fallback;
139	void				*data;
140};
141
142
143void		 iconvlist(int (*do_one) (unsigned int, const char * const *,
144		    void *), void *);
145const char	*iconv_canonicalize(const char *);
146int		 iconvctl(iconv_t, int, void *);
147__END_DECLS
148
149#endif /* !_ICONV_H_ */
150