jpayne@69: /* Copyright (C) 1999-2022 Free Software Foundation, Inc. jpayne@69: This file is part of the GNU LIBICONV Library. jpayne@69: jpayne@69: The GNU LIBICONV Library is free software; you can redistribute it jpayne@69: and/or modify it under the terms of the GNU Lesser General Public jpayne@69: License as published by the Free Software Foundation; either version 2.1 jpayne@69: of the License, or (at your option) any later version. jpayne@69: jpayne@69: The GNU LIBICONV Library is distributed in the hope that it will be jpayne@69: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of jpayne@69: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU jpayne@69: Lesser General Public License for more details. jpayne@69: jpayne@69: You should have received a copy of the GNU Lesser General Public jpayne@69: License along with the GNU LIBICONV Library; see the file COPYING.LIB. jpayne@69: If not, see . */ jpayne@69: jpayne@69: /* When installed, this file is called "iconv.h". */ jpayne@69: jpayne@69: #ifndef _LIBICONV_H jpayne@69: #define _LIBICONV_H jpayne@69: jpayne@69: #define _LIBICONV_VERSION 0x0111 /* version number: (major<<8) + minor */ jpayne@69: extern int _libiconv_version; /* Likewise */ jpayne@69: jpayne@69: /* We would like to #include any system header file which could define jpayne@69: iconv_t, 1. in order to eliminate the risk that the user gets compilation jpayne@69: errors because some other system header file includes /usr/include/iconv.h jpayne@69: which defines iconv_t or declares iconv after this file, 2. when compiling jpayne@69: for LIBICONV_PLUG, we need the proper iconv_t type in order to produce jpayne@69: binary compatible code. jpayne@69: But gcc's #include_next is not portable. Thus, once libiconv's iconv.h jpayne@69: has been installed in /usr/local/include, there is no way any more to jpayne@69: include the original /usr/include/iconv.h. We simply have to get away jpayne@69: without it. jpayne@69: Ad 1. The risk that a system header file does jpayne@69: #include "iconv.h" or #include_next "iconv.h" jpayne@69: is small. They all do #include . jpayne@69: Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It jpayne@69: has to be a scalar type because (iconv_t)(-1) is a possible return value jpayne@69: from iconv_open().) */ jpayne@69: jpayne@69: /* Define iconv_t ourselves. */ jpayne@69: #undef iconv_t jpayne@69: #define iconv_t libiconv_t jpayne@69: typedef void* iconv_t; jpayne@69: jpayne@69: /* Get size_t declaration. jpayne@69: Get wchar_t declaration if it exists. */ jpayne@69: #include jpayne@69: jpayne@69: /* Get errno declaration and values. */ jpayne@69: #include jpayne@69: /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS, jpayne@69: have EILSEQ in a different header. On these systems, define EILSEQ jpayne@69: ourselves. */ jpayne@69: #ifndef EILSEQ jpayne@69: #define EILSEQ jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* Allocates descriptor for code conversion from encoding ‘fromcode’ to jpayne@69: encoding ‘tocode’. */ jpayne@69: #ifndef LIBICONV_PLUG jpayne@69: #define iconv_open libiconv_open jpayne@69: #endif jpayne@69: extern iconv_t iconv_open (const char* tocode, const char* fromcode); jpayne@69: jpayne@69: /* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes jpayne@69: starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at jpayne@69: ‘*outbuf’. jpayne@69: Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount. jpayne@69: Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */ jpayne@69: #ifndef LIBICONV_PLUG jpayne@69: #define iconv libiconv jpayne@69: #endif jpayne@69: extern size_t iconv (iconv_t cd, char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft); jpayne@69: jpayne@69: /* Frees resources allocated for conversion descriptor ‘cd’. */ jpayne@69: #ifndef LIBICONV_PLUG jpayne@69: #define iconv_close libiconv_close jpayne@69: #endif jpayne@69: extern int iconv_close (iconv_t cd); jpayne@69: jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: #ifndef LIBICONV_PLUG jpayne@69: jpayne@69: /* Nonstandard extensions. */ jpayne@69: jpayne@69: #if 1 jpayne@69: #if 0 jpayne@69: /* Tru64 with Desktop Toolkit C has a bug: must be included before jpayne@69: . jpayne@69: BSD/OS 4.0.1 has a bug: , and must be jpayne@69: included before . */ jpayne@69: #include jpayne@69: #include jpayne@69: #include jpayne@69: #endif jpayne@69: #include jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: /* A type that holds all memory needed by a conversion descriptor. jpayne@69: A pointer to such an object can be used as an iconv_t. */ jpayne@69: typedef struct { jpayne@69: void* dummy1[28]; jpayne@69: #if 1 jpayne@69: mbstate_t dummy2; jpayne@69: #endif jpayne@69: } iconv_allocation_t; jpayne@69: jpayne@69: /* Allocates descriptor for code conversion from encoding ‘fromcode’ to jpayne@69: encoding ‘tocode’ into preallocated memory. Returns an error indicator jpayne@69: (0 or -1 with errno set). */ jpayne@69: #define iconv_open_into libiconv_open_into jpayne@69: extern int iconv_open_into (const char* tocode, const char* fromcode, jpayne@69: iconv_allocation_t* resultp); jpayne@69: jpayne@69: /* Control of attributes. */ jpayne@69: #define iconvctl libiconvctl jpayne@69: extern int iconvctl (iconv_t cd, int request, void* argument); jpayne@69: jpayne@69: /* Hook performed after every successful conversion of a Unicode character. */ jpayne@69: typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data); jpayne@69: /* Hook performed after every successful conversion of a wide character. */ jpayne@69: typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data); jpayne@69: /* Set of hooks. */ jpayne@69: struct iconv_hooks { jpayne@69: iconv_unicode_char_hook uc_hook; jpayne@69: iconv_wide_char_hook wc_hook; jpayne@69: void* data; jpayne@69: }; jpayne@69: jpayne@69: /* Fallback function. Invoked when a small number of bytes could not be jpayne@69: converted to a Unicode character. This function should process all jpayne@69: bytes from inbuf and may produce replacement Unicode characters by calling jpayne@69: the write_replacement callback repeatedly. */ jpayne@69: typedef void (*iconv_unicode_mb_to_uc_fallback) jpayne@69: (const char* inbuf, size_t inbufsize, jpayne@69: void (*write_replacement) (const unsigned int *buf, size_t buflen, jpayne@69: void* callback_arg), jpayne@69: void* callback_arg, jpayne@69: void* data); jpayne@69: /* Fallback function. Invoked when a Unicode character could not be converted jpayne@69: to the target encoding. This function should process the character and jpayne@69: may produce replacement bytes (in the target encoding) by calling the jpayne@69: write_replacement callback repeatedly. */ jpayne@69: typedef void (*iconv_unicode_uc_to_mb_fallback) jpayne@69: (unsigned int code, jpayne@69: void (*write_replacement) (const char *buf, size_t buflen, jpayne@69: void* callback_arg), jpayne@69: void* callback_arg, jpayne@69: void* data); jpayne@69: #if 1 jpayne@69: /* Fallback function. Invoked when a number of bytes could not be converted to jpayne@69: a wide character. This function should process all bytes from inbuf and may jpayne@69: produce replacement wide characters by calling the write_replacement jpayne@69: callback repeatedly. */ jpayne@69: typedef void (*iconv_wchar_mb_to_wc_fallback) jpayne@69: (const char* inbuf, size_t inbufsize, jpayne@69: void (*write_replacement) (const wchar_t *buf, size_t buflen, jpayne@69: void* callback_arg), jpayne@69: void* callback_arg, jpayne@69: void* data); jpayne@69: /* Fallback function. Invoked when a wide character could not be converted to jpayne@69: the target encoding. This function should process the character and may jpayne@69: produce replacement bytes (in the target encoding) by calling the jpayne@69: write_replacement callback repeatedly. */ jpayne@69: typedef void (*iconv_wchar_wc_to_mb_fallback) jpayne@69: (wchar_t code, jpayne@69: void (*write_replacement) (const char *buf, size_t buflen, jpayne@69: void* callback_arg), jpayne@69: void* callback_arg, jpayne@69: void* data); jpayne@69: #else jpayne@69: /* If the wchar_t type does not exist, these two fallback functions are never jpayne@69: invoked. Their argument list therefore does not matter. */ jpayne@69: typedef void (*iconv_wchar_mb_to_wc_fallback) (); jpayne@69: typedef void (*iconv_wchar_wc_to_mb_fallback) (); jpayne@69: #endif jpayne@69: /* Set of fallbacks. */ jpayne@69: struct iconv_fallbacks { jpayne@69: iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback; jpayne@69: iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback; jpayne@69: iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback; jpayne@69: iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback; jpayne@69: void* data; jpayne@69: }; jpayne@69: jpayne@69: /* Requests for iconvctl. */ jpayne@69: #define ICONV_TRIVIALP 0 /* int *argument */ jpayne@69: #define ICONV_GET_TRANSLITERATE 1 /* int *argument */ jpayne@69: #define ICONV_SET_TRANSLITERATE 2 /* const int *argument */ jpayne@69: #define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */ jpayne@69: #define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */ jpayne@69: #define ICONV_SET_HOOKS 5 /* const struct iconv_hooks *argument */ jpayne@69: #define ICONV_SET_FALLBACKS 6 /* const struct iconv_fallbacks *argument */ jpayne@69: jpayne@69: /* Listing of locale independent encodings. */ jpayne@69: #define iconvlist libiconvlist jpayne@69: extern void iconvlist (int (*do_one) (unsigned int namescount, jpayne@69: const char * const * names, jpayne@69: void* data), jpayne@69: void* data); jpayne@69: jpayne@69: /* Canonicalize an encoding name. jpayne@69: The result is either a canonical encoding name, or name itself. */ jpayne@69: extern const char * iconv_canonicalize (const char * name); jpayne@69: jpayne@69: /* Support for relocatable packages. */ jpayne@69: jpayne@69: /* Sets the original and the current installation prefix of the package. jpayne@69: Relocation simply replaces a pathname starting with the original prefix jpayne@69: by the corresponding pathname with the current prefix instead. Both jpayne@69: prefixes should be directory names without trailing slash (i.e. use "" jpayne@69: instead of "/"). */ jpayne@69: extern void libiconv_set_relocation_prefix (const char *orig_prefix, jpayne@69: const char *curr_prefix); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: #endif /* _LIBICONV_H */