1 /* Copyright (C) 1997-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #define _GCONV_INT_H 1
23 #include <stdlib.h> /* For alloca used in macro below. */
24 #include <ctype.h> /* For __toupper_l used in macro below. */
25 #include <string.h> /* For strlen et al used in macro below. */
26 #include <libc-lock.h>
31 /* Structure for alias definition. Simply two strings. */
39 /* Structure describing one loaded shared object. This normally are
40 objects to perform conversation but as a special case the db shared
41 object is also handled. */
42 struct __gconv_loaded_object
44 /* Name of the object. It must be the first structure element. */
47 /* Reference counter for the db functionality. If no conversion is
48 needed we unload the db library. */
51 /* The handle for the shared object. */
54 /* Pointer to the functions the module defines. */
56 __gconv_init_fct init_fct
;
57 __gconv_end_fct end_fct
;
61 /* Description for an available conversion module. */
64 const char *from_string
;
65 const char *to_string
;
70 const char *module_name
;
72 struct gconv_module
*left
; /* Prefix smaller. */
73 struct gconv_module
*same
; /* List of entries with identical prefix. */
74 struct gconv_module
*right
; /* Prefix larger. */
78 /* Flags for `gconv_open'. */
81 GCONV_AVOID_NOCONV
= 1 << 0
84 /* When GCONV_AVOID_NOCONV is set and no conversion is needed,
85 __GCONV_NULCONV should be returned. */
91 /* Global variables. */
93 /* Database of alias names. */
94 extern void *__gconv_alias_db attribute_hidden
;
96 /* Array with available modules. */
97 extern struct gconv_module
*__gconv_modules_db attribute_hidden
;
99 /* Value of the GCONV_PATH environment variable. */
100 extern const char *__gconv_path_envvar attribute_hidden
;
102 /* Lock for the conversion database content. */
103 __libc_lock_define (extern, __gconv_lock attribute_hidden
)
106 /* The gconv functions expects the name to be in upper case and complete,
107 including the trailing slashes if necessary. */
108 #define norm_add_slashes(str,suffix) \
110 const char *cp = (str); \
114 const size_t suffix_len = strlen (suffix); \
116 while (*cp != '\0') \
120 tmp = result = __alloca (cp - (str) + 3 + suffix_len); \
122 while (*cp != '\0') \
123 *tmp++ = __toupper_l (*cp++, _nl_C_locobj_ptr); \
130 if (suffix_len != 0) \
131 tmp = __mempcpy (tmp, suffix, suffix_len); \
139 /* Return in *HANDLE decriptor for transformation from FROMSET to TOSET. */
140 extern int __gconv_open (const char *toset
, const char *fromset
,
141 __gconv_t
*handle
, int flags
)
144 /* Free resources associated with transformation descriptor CD. */
145 extern int __gconv_close (__gconv_t cd
)
148 /* Transform at most *INBYTESLEFT bytes from buffer starting at *INBUF
149 according to rules described by CD and place up to *OUTBYTESLEFT
150 bytes in buffer starting at *OUTBUF. Return number of non-identical
151 conversions in *IRREVERSIBLE if this pointer is not null. */
152 extern int __gconv (__gconv_t cd
, const unsigned char **inbuf
,
153 const unsigned char *inbufend
, unsigned char **outbuf
,
154 unsigned char *outbufend
, size_t *irreversible
)
157 /* Return in *HANDLE a pointer to an array with *NSTEPS elements describing
158 the single steps necessary for transformation from FROMSET to TOSET. */
159 extern int __gconv_find_transform (const char *toset
, const char *fromset
,
160 struct __gconv_step
**handle
,
161 size_t *nsteps
, int flags
)
164 /* Search for transformation in cache data. */
165 extern int __gconv_lookup_cache (const char *toset
, const char *fromset
,
166 struct __gconv_step
**handle
, size_t *nsteps
,
170 /* Compare the two name for whether they are after alias expansion the
171 same. This function uses the cache and fails if none is
173 extern int __gconv_compare_alias_cache (const char *name1
, const char *name2
,
177 /* Free data associated with a step's structure. */
178 extern void __gconv_release_step (struct __gconv_step
*step
)
181 /* Read all the configuration data and cache it if not done so already. */
182 extern void __gconv_load_conf (void) attribute_hidden
;
184 /* Try to read module cache file. */
185 extern int __gconv_load_cache (void) attribute_hidden
;
187 /* Retrieve pointer to internal cache. */
188 extern void *__gconv_get_cache (void);
190 /* Retrieve pointer to internal module database. */
191 extern struct gconv_module
*__gconv_get_modules_db (void);
193 /* Retrieve pointer to internal alias database. */
194 extern void *__gconv_get_alias_db (void);
196 /* Comparison function to search alias. */
197 extern int __gconv_alias_compare (const void *p1
, const void *p2
)
200 /* Clear reference to transformation step implementations which might
201 cause the code to be unloaded. */
202 extern int __gconv_close_transform (struct __gconv_step
*steps
,
206 /* Free all resources allocated for the transformation record when
208 extern void __gconv_release_cache (struct __gconv_step
*steps
, size_t nsteps
)
211 /* Load shared object named by NAME. If already loaded increment reference
213 extern struct __gconv_loaded_object
*__gconv_find_shlib (const char *name
)
216 /* Release shared object. If no further reference is available unload
218 extern void __gconv_release_shlib (struct __gconv_loaded_object
*handle
)
221 /* Fill STEP with information about builtin module with NAME. */
222 extern void __gconv_get_builtin_trans (const char *name
,
223 struct __gconv_step
*step
)
226 libc_hidden_proto (__gconv_transliterate
)
228 /* If NAME is an codeset alias expand it. */
229 extern int __gconv_compare_alias (const char *name1
, const char *name2
)
233 /* Builtin transformations. */
235 # define __BUILTIN_TRANSFORM(Name) \
236 extern int Name (struct __gconv_step *step, \
237 struct __gconv_step_data *data, \
238 const unsigned char **inbuf, \
239 const unsigned char *inbufend, \
240 unsigned char **outbufstart, size_t *irreversible, \
241 int do_flush, int consume_incomplete)
243 __BUILTIN_TRANSFORM (__gconv_transform_ascii_internal
);
244 __BUILTIN_TRANSFORM (__gconv_transform_internal_ascii
);
245 __BUILTIN_TRANSFORM (__gconv_transform_utf8_internal
);
246 __BUILTIN_TRANSFORM (__gconv_transform_internal_utf8
);
247 __BUILTIN_TRANSFORM (__gconv_transform_ucs2_internal
);
248 __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2
);
249 __BUILTIN_TRANSFORM (__gconv_transform_ucs2reverse_internal
);
250 __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs2reverse
);
251 __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4
);
252 __BUILTIN_TRANSFORM (__gconv_transform_ucs4_internal
);
253 __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4le
);
254 __BUILTIN_TRANSFORM (__gconv_transform_ucs4le_internal
);
255 __BUILTIN_TRANSFORM (__gconv_transform_internal_utf16
);
256 __BUILTIN_TRANSFORM (__gconv_transform_utf16_internal
);
257 # undef __BUITLIN_TRANSFORM
259 /* Specialized conversion function for a single byte to INTERNAL, recognizing
260 only ASCII characters. */
261 extern wint_t __gconv_btwoc_ascii (struct __gconv_step
*step
, unsigned char c
);
267 #endif /* gconv_int.h */