gconv.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Copyright (C) 1997-2020 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. <https://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. #include <bits/types/__mbstate_t.h>
  21. #include <bits/types/wint_t.h>
  22. #define __need_size_t
  23. #define __need_wchar_t
  24. #include <stddef.h>
  25. /* ISO 10646 value used to signal invalid value. */
  26. #define __UNKNOWN_10646_CHAR ((wchar_t) 0xfffd)
  27. /* Error codes for gconv functions. */
  28. enum
  29. {
  30. __GCONV_OK = 0,
  31. __GCONV_NOCONV,
  32. __GCONV_NODB,
  33. __GCONV_NOMEM,
  34. __GCONV_EMPTY_INPUT,
  35. __GCONV_FULL_OUTPUT,
  36. __GCONV_ILLEGAL_INPUT,
  37. __GCONV_INCOMPLETE_INPUT,
  38. __GCONV_ILLEGAL_DESCRIPTOR,
  39. __GCONV_INTERNAL_ERROR
  40. };
  41. /* Flags the `__gconv_open' function can set. */
  42. enum
  43. {
  44. __GCONV_IS_LAST = 0x0001,
  45. __GCONV_IGNORE_ERRORS = 0x0002,
  46. __GCONV_SWAP = 0x0004,
  47. __GCONV_TRANSLIT = 0x0008
  48. };
  49. /* Forward declarations. */
  50. struct __gconv_step;
  51. struct __gconv_step_data;
  52. struct __gconv_loaded_object;
  53. /* Type of a conversion function. */
  54. typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *,
  55. const unsigned char **, const unsigned char *,
  56. unsigned char **, size_t *, int, int);
  57. /* Type of a specialized conversion function for a single byte to INTERNAL. */
  58. typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char);
  59. /* Constructor and destructor for local data for conversion step. */
  60. typedef int (*__gconv_init_fct) (struct __gconv_step *);
  61. typedef void (*__gconv_end_fct) (struct __gconv_step *);
  62. /* Description of a conversion step. */
  63. struct __gconv_step
  64. {
  65. struct __gconv_loaded_object *__shlib_handle;
  66. const char *__modname;
  67. /* For internal use by glibc. (Accesses to this member must occur
  68. when the internal __gconv_lock mutex is acquired). */
  69. int __counter;
  70. char *__from_name;
  71. char *__to_name;
  72. __gconv_fct __fct;
  73. __gconv_btowc_fct __btowc_fct;
  74. __gconv_init_fct __init_fct;
  75. __gconv_end_fct __end_fct;
  76. /* Information about the number of bytes needed or produced in this
  77. step. This helps optimizing the buffer sizes. */
  78. int __min_needed_from;
  79. int __max_needed_from;
  80. int __min_needed_to;
  81. int __max_needed_to;
  82. /* Flag whether this is a stateful encoding or not. */
  83. int __stateful;
  84. void *__data; /* Pointer to step-local data. */
  85. };
  86. /* Additional data for steps in use of conversion descriptor. This is
  87. allocated by the `init' function. */
  88. struct __gconv_step_data
  89. {
  90. unsigned char *__outbuf; /* Output buffer for this step. */
  91. unsigned char *__outbufend; /* Address of first byte after the output
  92. buffer. */
  93. /* Is this the last module in the chain. */
  94. int __flags;
  95. /* Counter for number of invocations of the module function for this
  96. descriptor. */
  97. int __invocation_counter;
  98. /* Flag whether this is an internal use of the module (in the mb*towc*
  99. and wc*tomb* functions) or regular with iconv(3). */
  100. int __internal_use;
  101. __mbstate_t *__statep;
  102. __mbstate_t __state; /* This element must not be used directly by
  103. any module; always use STATEP! */
  104. };
  105. /* Combine conversion step description with data. */
  106. typedef struct __gconv_info
  107. {
  108. size_t __nsteps;
  109. struct __gconv_step *__steps;
  110. __extension__ struct __gconv_step_data __data[0];
  111. } *__gconv_t;
  112. #endif /* gconv.h */