gconv.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* Copyright (C) 1997-2016 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, see
  13. <http://www.gnu.org/licenses/>. */
  14. /* This header provides no interface for a user to the internals of
  15. the gconv implementation in the libc. Therefore there is no use
  16. for these definitions beside for writing additional gconv modules. */
  17. #ifndef _GCONV_H
  18. #define _GCONV_H 1
  19. #include <features.h>
  20. #define __need_mbstate_t
  21. #define __need_wint_t
  22. #include <wchar.h>
  23. #define __need_size_t
  24. #define __need_wchar_t
  25. #include <stddef.h>
  26. /* ISO 10646 value used to signal invalid value. */
  27. #define __UNKNOWN_10646_CHAR ((wchar_t) 0xfffd)
  28. /* Error codes for gconv functions. */
  29. enum
  30. {
  31. __GCONV_OK = 0,
  32. __GCONV_NOCONV,
  33. __GCONV_NODB,
  34. __GCONV_NOMEM,
  35. __GCONV_EMPTY_INPUT,
  36. __GCONV_FULL_OUTPUT,
  37. __GCONV_ILLEGAL_INPUT,
  38. __GCONV_INCOMPLETE_INPUT,
  39. __GCONV_ILLEGAL_DESCRIPTOR,
  40. __GCONV_INTERNAL_ERROR
  41. };
  42. /* Flags the `__gconv_open' function can set. */
  43. enum
  44. {
  45. __GCONV_IS_LAST = 0x0001,
  46. __GCONV_IGNORE_ERRORS = 0x0002,
  47. __GCONV_SWAP = 0x0004,
  48. __GCONV_TRANSLIT = 0x0008
  49. };
  50. /* Forward declarations. */
  51. struct __gconv_step;
  52. struct __gconv_step_data;
  53. struct __gconv_loaded_object;
  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. /* Description of a conversion step. */
  64. struct __gconv_step
  65. {
  66. struct __gconv_loaded_object *__shlib_handle;
  67. const char *__modname;
  68. int __counter;
  69. char *__from_name;
  70. char *__to_name;
  71. __gconv_fct __fct;
  72. __gconv_btowc_fct __btowc_fct;
  73. __gconv_init_fct __init_fct;
  74. __gconv_end_fct __end_fct;
  75. /* Information about the number of bytes needed or produced in this
  76. step. This helps optimizing the buffer sizes. */
  77. int __min_needed_from;
  78. int __max_needed_from;
  79. int __min_needed_to;
  80. int __max_needed_to;
  81. /* Flag whether this is a stateful encoding or not. */
  82. int __stateful;
  83. void *__data; /* Pointer to step-local data. */
  84. };
  85. /* Additional data for steps in use of conversion descriptor. This is
  86. allocated by the `init' function. */
  87. struct __gconv_step_data
  88. {
  89. unsigned char *__outbuf; /* Output buffer for this step. */
  90. unsigned char *__outbufend; /* Address of first byte after the output
  91. buffer. */
  92. /* Is this the last module in the chain. */
  93. int __flags;
  94. /* Counter for number of invocations of the module function for this
  95. descriptor. */
  96. int __invocation_counter;
  97. /* Flag whether this is an internal use of the module (in the mb*towc*
  98. and wc*tomb* functions) or regular with iconv(3). */
  99. int __internal_use;
  100. __mbstate_t *__statep;
  101. __mbstate_t __state; /* This element must not be used directly by
  102. any module; always use STATEP! */
  103. };
  104. /* Combine conversion step description with data. */
  105. typedef struct __gconv_info
  106. {
  107. size_t __nsteps;
  108. struct __gconv_step *__steps;
  109. __extension__ struct __gconv_step_data __data __flexarr;
  110. } *__gconv_t;
  111. /* Transliteration using the locale's data. */
  112. extern int __gconv_transliterate (struct __gconv_step *step,
  113. struct __gconv_step_data *step_data,
  114. const unsigned char *inbufstart,
  115. const unsigned char **inbufp,
  116. const unsigned char *inbufend,
  117. unsigned char **outbufstart,
  118. size_t *irreversible);
  119. #endif /* gconv.h */