iconv.h 4.2 KB

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