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