gconv.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* Copyright (C) 1997-1999, 2000-2002, 2007 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. /* This header provides no interface for a user to the internals of
  16. the gconv implementation in the libc. Therefore there is no use
  17. for these definitions beside for writing additional gconv modules. */
  18. #ifndef _GCONV_H
  19. #define _GCONV_H 1
  20. #include <features.h>
  21. #define __need_mbstate_t
  22. #define __need_wint_t
  23. #include <wchar.h>
  24. #define __need_size_t
  25. #define __need_wchar_t
  26. #include <stddef.h>
  27. /* ISO 10646 value used to signal invalid value. */
  28. #define __UNKNOWN_10646_CHAR ((wchar_t) 0xfffd)
  29. /* Error codes for gconv functions. */
  30. enum
  31. {
  32. __GCONV_OK = 0,
  33. __GCONV_NOCONV,
  34. __GCONV_NODB,
  35. __GCONV_NOMEM,
  36. __GCONV_EMPTY_INPUT,
  37. __GCONV_FULL_OUTPUT,
  38. __GCONV_ILLEGAL_INPUT,
  39. __GCONV_INCOMPLETE_INPUT,
  40. __GCONV_ILLEGAL_DESCRIPTOR,
  41. __GCONV_INTERNAL_ERROR
  42. };
  43. /* Flags the `__gconv_open' function can set. */
  44. enum
  45. {
  46. __GCONV_IS_LAST = 0x0001,
  47. __GCONV_IGNORE_ERRORS = 0x0002
  48. };
  49. /* Forward declarations. */
  50. struct __gconv_step;
  51. struct __gconv_step_data;
  52. struct __gconv_loaded_object;
  53. struct __gconv_trans_data;
  54. /* Type of a conversion function. */
  55. typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *,
  56. __const unsigned char **, __const unsigned char *,
  57. unsigned char **, size_t *, int, int);
  58. /* Type of a specialized conversion function for a single byte to INTERNAL. */
  59. typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char);
  60. /* Constructor and destructor for local data for conversion step. */
  61. typedef int (*__gconv_init_fct) (struct __gconv_step *);
  62. typedef void (*__gconv_end_fct) (struct __gconv_step *);
  63. /* Type of a transliteration/transscription function. */
  64. typedef int (*__gconv_trans_fct) (struct __gconv_step *,
  65. struct __gconv_step_data *, void *,
  66. __const unsigned char *,
  67. __const unsigned char **,
  68. __const unsigned char *, unsigned char **,
  69. size_t *);
  70. /* Function to call to provide transliteration module with context. */
  71. typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *,
  72. __const unsigned char *,
  73. unsigned char *, unsigned char *);
  74. /* Function to query module about supported encoded character sets. */
  75. typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***,
  76. size_t *);
  77. /* Constructor and destructor for local data for transliteration. */
  78. typedef int (*__gconv_trans_init_fct) (void **, const char *);
  79. typedef void (*__gconv_trans_end_fct) (void *);
  80. struct __gconv_trans_data
  81. {
  82. /* Transliteration/Transscription function. */
  83. __gconv_trans_fct __trans_fct;
  84. __gconv_trans_context_fct __trans_context_fct;
  85. __gconv_trans_end_fct __trans_end_fct;
  86. void *__data;
  87. struct __gconv_trans_data *__next;
  88. };
  89. /* Description of a conversion step. */
  90. struct __gconv_step
  91. {
  92. struct __gconv_loaded_object *__shlib_handle;
  93. __const char *__modname;
  94. int __counter;
  95. char *__from_name;
  96. char *__to_name;
  97. __gconv_fct __fct;
  98. __gconv_btowc_fct __btowc_fct;
  99. __gconv_init_fct __init_fct;
  100. __gconv_end_fct __end_fct;
  101. /* Information about the number of bytes needed or produced in this
  102. step. This helps optimizing the buffer sizes. */
  103. int __min_needed_from;
  104. int __max_needed_from;
  105. int __min_needed_to;
  106. int __max_needed_to;
  107. /* Flag whether this is a stateful encoding or not. */
  108. int __stateful;
  109. void *__data; /* Pointer to step-local data. */
  110. };
  111. /* Additional data for steps in use of conversion descriptor. This is
  112. allocated by the `init' function. */
  113. struct __gconv_step_data
  114. {
  115. unsigned char *__outbuf; /* Output buffer for this step. */
  116. unsigned char *__outbufend; /* Address of first byte after the output
  117. buffer. */
  118. /* Is this the last module in the chain. */
  119. int __flags;
  120. /* Counter for number of invocations of the module function for this
  121. descriptor. */
  122. int __invocation_counter;
  123. /* Flag whether this is an internal use of the module (in the mb*towc*
  124. and wc*tomb* functions) or regular with iconv(3). */
  125. int __internal_use;
  126. __mbstate_t *__statep;
  127. __mbstate_t __state; /* This element must not be used directly by
  128. any module; always use STATEP! */
  129. /* Transliteration information. */
  130. struct __gconv_trans_data *__trans;
  131. };
  132. /* Combine conversion step description with data. */
  133. typedef struct __gconv_info
  134. {
  135. size_t __nsteps;
  136. struct __gconv_step *__steps;
  137. __extension__ struct __gconv_step_data __data __flexarr;
  138. } *__gconv_t;
  139. #endif /* gconv.h */