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