xref: /netbsd-src/external/gpl3/binutils.old/dist/intl/loadmsgcat.c (revision 16dce51364ebe8aeafbae46bc5aa167b8115bc45)
1*16dce513Schristos /* Load needed message catalogs.
2*16dce513Schristos    Copyright (C) 1995-1999, 2000-2003 Free Software Foundation, Inc.
3*16dce513Schristos 
4*16dce513Schristos    This program is free software; you can redistribute it and/or modify it
5*16dce513Schristos    under the terms of the GNU Library General Public License as published
6*16dce513Schristos    by the Free Software Foundation; either version 2, or (at your option)
7*16dce513Schristos    any later version.
8*16dce513Schristos 
9*16dce513Schristos    This program is distributed in the hope that it will be useful,
10*16dce513Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
11*16dce513Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12*16dce513Schristos    Library General Public License for more details.
13*16dce513Schristos 
14*16dce513Schristos    You should have received a copy of the GNU Library General Public
15*16dce513Schristos    License along with this program; if not, write to the Free Software
16*16dce513Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
17*16dce513Schristos    USA.  */
18*16dce513Schristos 
19*16dce513Schristos /* Tell glibc's <string.h> to provide a prototype for mempcpy().
20*16dce513Schristos    This must come before <config.h> because <config.h> may include
21*16dce513Schristos    <features.h>, and once <features.h> has been included, it's too late.  */
22*16dce513Schristos #ifndef _GNU_SOURCE
23*16dce513Schristos # define _GNU_SOURCE    1
24*16dce513Schristos #endif
25*16dce513Schristos 
26*16dce513Schristos #ifdef HAVE_CONFIG_H
27*16dce513Schristos # include <config.h>
28*16dce513Schristos #endif
29*16dce513Schristos 
30*16dce513Schristos #include <ctype.h>
31*16dce513Schristos #include <errno.h>
32*16dce513Schristos #include <fcntl.h>
33*16dce513Schristos #include <sys/types.h>
34*16dce513Schristos #include <sys/stat.h>
35*16dce513Schristos 
36*16dce513Schristos #ifdef __GNUC__
37*16dce513Schristos # undef  alloca
38*16dce513Schristos # define alloca __builtin_alloca
39*16dce513Schristos # define HAVE_ALLOCA 1
40*16dce513Schristos #else
41*16dce513Schristos # ifdef _MSC_VER
42*16dce513Schristos #  include <malloc.h>
43*16dce513Schristos #  define alloca _alloca
44*16dce513Schristos # else
45*16dce513Schristos #  if defined HAVE_ALLOCA_H || defined _LIBC
46*16dce513Schristos #   include <alloca.h>
47*16dce513Schristos #  else
48*16dce513Schristos #   ifdef _AIX
49*16dce513Schristos  #pragma alloca
50*16dce513Schristos #   else
51*16dce513Schristos #    ifndef alloca
52*16dce513Schristos char *alloca ();
53*16dce513Schristos #    endif
54*16dce513Schristos #   endif
55*16dce513Schristos #  endif
56*16dce513Schristos # endif
57*16dce513Schristos #endif
58*16dce513Schristos 
59*16dce513Schristos #include <stdlib.h>
60*16dce513Schristos #include <string.h>
61*16dce513Schristos 
62*16dce513Schristos #if defined HAVE_UNISTD_H || defined _LIBC
63*16dce513Schristos # include <unistd.h>
64*16dce513Schristos #endif
65*16dce513Schristos 
66*16dce513Schristos #ifdef _LIBC
67*16dce513Schristos # include <langinfo.h>
68*16dce513Schristos # include <locale.h>
69*16dce513Schristos #endif
70*16dce513Schristos 
71*16dce513Schristos #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
72*16dce513Schristos     || (defined _LIBC && defined _POSIX_MAPPED_FILES)
73*16dce513Schristos # include <sys/mman.h>
74*16dce513Schristos # undef HAVE_MMAP
75*16dce513Schristos # define HAVE_MMAP	1
76*16dce513Schristos #else
77*16dce513Schristos # undef HAVE_MMAP
78*16dce513Schristos #endif
79*16dce513Schristos 
80*16dce513Schristos #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
81*16dce513Schristos # include <stdint.h>
82*16dce513Schristos #endif
83*16dce513Schristos #if defined HAVE_INTTYPES_H || defined _LIBC
84*16dce513Schristos # include <inttypes.h>
85*16dce513Schristos #endif
86*16dce513Schristos 
87*16dce513Schristos #include "gmo.h"
88*16dce513Schristos #include "gettextP.h"
89*16dce513Schristos #include "hash-string.h"
90*16dce513Schristos #include "plural-exp.h"
91*16dce513Schristos 
92*16dce513Schristos #ifdef _LIBC
93*16dce513Schristos # include "../locale/localeinfo.h"
94*16dce513Schristos #endif
95*16dce513Schristos 
96*16dce513Schristos /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
97*16dce513Schristos    Note that our fallback values need not be literal strings, because we don't
98*16dce513Schristos    use them with preprocessor string concatenation.  */
99*16dce513Schristos #if !defined PRId8 || PRI_MACROS_BROKEN
100*16dce513Schristos # undef PRId8
101*16dce513Schristos # define PRId8 "d"
102*16dce513Schristos #endif
103*16dce513Schristos #if !defined PRIi8 || PRI_MACROS_BROKEN
104*16dce513Schristos # undef PRIi8
105*16dce513Schristos # define PRIi8 "i"
106*16dce513Schristos #endif
107*16dce513Schristos #if !defined PRIo8 || PRI_MACROS_BROKEN
108*16dce513Schristos # undef PRIo8
109*16dce513Schristos # define PRIo8 "o"
110*16dce513Schristos #endif
111*16dce513Schristos #if !defined PRIu8 || PRI_MACROS_BROKEN
112*16dce513Schristos # undef PRIu8
113*16dce513Schristos # define PRIu8 "u"
114*16dce513Schristos #endif
115*16dce513Schristos #if !defined PRIx8 || PRI_MACROS_BROKEN
116*16dce513Schristos # undef PRIx8
117*16dce513Schristos # define PRIx8 "x"
118*16dce513Schristos #endif
119*16dce513Schristos #if !defined PRIX8 || PRI_MACROS_BROKEN
120*16dce513Schristos # undef PRIX8
121*16dce513Schristos # define PRIX8 "X"
122*16dce513Schristos #endif
123*16dce513Schristos #if !defined PRId16 || PRI_MACROS_BROKEN
124*16dce513Schristos # undef PRId16
125*16dce513Schristos # define PRId16 "d"
126*16dce513Schristos #endif
127*16dce513Schristos #if !defined PRIi16 || PRI_MACROS_BROKEN
128*16dce513Schristos # undef PRIi16
129*16dce513Schristos # define PRIi16 "i"
130*16dce513Schristos #endif
131*16dce513Schristos #if !defined PRIo16 || PRI_MACROS_BROKEN
132*16dce513Schristos # undef PRIo16
133*16dce513Schristos # define PRIo16 "o"
134*16dce513Schristos #endif
135*16dce513Schristos #if !defined PRIu16 || PRI_MACROS_BROKEN
136*16dce513Schristos # undef PRIu16
137*16dce513Schristos # define PRIu16 "u"
138*16dce513Schristos #endif
139*16dce513Schristos #if !defined PRIx16 || PRI_MACROS_BROKEN
140*16dce513Schristos # undef PRIx16
141*16dce513Schristos # define PRIx16 "x"
142*16dce513Schristos #endif
143*16dce513Schristos #if !defined PRIX16 || PRI_MACROS_BROKEN
144*16dce513Schristos # undef PRIX16
145*16dce513Schristos # define PRIX16 "X"
146*16dce513Schristos #endif
147*16dce513Schristos #if !defined PRId32 || PRI_MACROS_BROKEN
148*16dce513Schristos # undef PRId32
149*16dce513Schristos # define PRId32 "d"
150*16dce513Schristos #endif
151*16dce513Schristos #if !defined PRIi32 || PRI_MACROS_BROKEN
152*16dce513Schristos # undef PRIi32
153*16dce513Schristos # define PRIi32 "i"
154*16dce513Schristos #endif
155*16dce513Schristos #if !defined PRIo32 || PRI_MACROS_BROKEN
156*16dce513Schristos # undef PRIo32
157*16dce513Schristos # define PRIo32 "o"
158*16dce513Schristos #endif
159*16dce513Schristos #if !defined PRIu32 || PRI_MACROS_BROKEN
160*16dce513Schristos # undef PRIu32
161*16dce513Schristos # define PRIu32 "u"
162*16dce513Schristos #endif
163*16dce513Schristos #if !defined PRIx32 || PRI_MACROS_BROKEN
164*16dce513Schristos # undef PRIx32
165*16dce513Schristos # define PRIx32 "x"
166*16dce513Schristos #endif
167*16dce513Schristos #if !defined PRIX32 || PRI_MACROS_BROKEN
168*16dce513Schristos # undef PRIX32
169*16dce513Schristos # define PRIX32 "X"
170*16dce513Schristos #endif
171*16dce513Schristos #if !defined PRId64 || PRI_MACROS_BROKEN
172*16dce513Schristos # undef PRId64
173*16dce513Schristos # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
174*16dce513Schristos #endif
175*16dce513Schristos #if !defined PRIi64 || PRI_MACROS_BROKEN
176*16dce513Schristos # undef PRIi64
177*16dce513Schristos # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
178*16dce513Schristos #endif
179*16dce513Schristos #if !defined PRIo64 || PRI_MACROS_BROKEN
180*16dce513Schristos # undef PRIo64
181*16dce513Schristos # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
182*16dce513Schristos #endif
183*16dce513Schristos #if !defined PRIu64 || PRI_MACROS_BROKEN
184*16dce513Schristos # undef PRIu64
185*16dce513Schristos # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
186*16dce513Schristos #endif
187*16dce513Schristos #if !defined PRIx64 || PRI_MACROS_BROKEN
188*16dce513Schristos # undef PRIx64
189*16dce513Schristos # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
190*16dce513Schristos #endif
191*16dce513Schristos #if !defined PRIX64 || PRI_MACROS_BROKEN
192*16dce513Schristos # undef PRIX64
193*16dce513Schristos # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
194*16dce513Schristos #endif
195*16dce513Schristos #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
196*16dce513Schristos # undef PRIdLEAST8
197*16dce513Schristos # define PRIdLEAST8 "d"
198*16dce513Schristos #endif
199*16dce513Schristos #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
200*16dce513Schristos # undef PRIiLEAST8
201*16dce513Schristos # define PRIiLEAST8 "i"
202*16dce513Schristos #endif
203*16dce513Schristos #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
204*16dce513Schristos # undef PRIoLEAST8
205*16dce513Schristos # define PRIoLEAST8 "o"
206*16dce513Schristos #endif
207*16dce513Schristos #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
208*16dce513Schristos # undef PRIuLEAST8
209*16dce513Schristos # define PRIuLEAST8 "u"
210*16dce513Schristos #endif
211*16dce513Schristos #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
212*16dce513Schristos # undef PRIxLEAST8
213*16dce513Schristos # define PRIxLEAST8 "x"
214*16dce513Schristos #endif
215*16dce513Schristos #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
216*16dce513Schristos # undef PRIXLEAST8
217*16dce513Schristos # define PRIXLEAST8 "X"
218*16dce513Schristos #endif
219*16dce513Schristos #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
220*16dce513Schristos # undef PRIdLEAST16
221*16dce513Schristos # define PRIdLEAST16 "d"
222*16dce513Schristos #endif
223*16dce513Schristos #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
224*16dce513Schristos # undef PRIiLEAST16
225*16dce513Schristos # define PRIiLEAST16 "i"
226*16dce513Schristos #endif
227*16dce513Schristos #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
228*16dce513Schristos # undef PRIoLEAST16
229*16dce513Schristos # define PRIoLEAST16 "o"
230*16dce513Schristos #endif
231*16dce513Schristos #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
232*16dce513Schristos # undef PRIuLEAST16
233*16dce513Schristos # define PRIuLEAST16 "u"
234*16dce513Schristos #endif
235*16dce513Schristos #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
236*16dce513Schristos # undef PRIxLEAST16
237*16dce513Schristos # define PRIxLEAST16 "x"
238*16dce513Schristos #endif
239*16dce513Schristos #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
240*16dce513Schristos # undef PRIXLEAST16
241*16dce513Schristos # define PRIXLEAST16 "X"
242*16dce513Schristos #endif
243*16dce513Schristos #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
244*16dce513Schristos # undef PRIdLEAST32
245*16dce513Schristos # define PRIdLEAST32 "d"
246*16dce513Schristos #endif
247*16dce513Schristos #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
248*16dce513Schristos # undef PRIiLEAST32
249*16dce513Schristos # define PRIiLEAST32 "i"
250*16dce513Schristos #endif
251*16dce513Schristos #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
252*16dce513Schristos # undef PRIoLEAST32
253*16dce513Schristos # define PRIoLEAST32 "o"
254*16dce513Schristos #endif
255*16dce513Schristos #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
256*16dce513Schristos # undef PRIuLEAST32
257*16dce513Schristos # define PRIuLEAST32 "u"
258*16dce513Schristos #endif
259*16dce513Schristos #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
260*16dce513Schristos # undef PRIxLEAST32
261*16dce513Schristos # define PRIxLEAST32 "x"
262*16dce513Schristos #endif
263*16dce513Schristos #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
264*16dce513Schristos # undef PRIXLEAST32
265*16dce513Schristos # define PRIXLEAST32 "X"
266*16dce513Schristos #endif
267*16dce513Schristos #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
268*16dce513Schristos # undef PRIdLEAST64
269*16dce513Schristos # define PRIdLEAST64 PRId64
270*16dce513Schristos #endif
271*16dce513Schristos #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
272*16dce513Schristos # undef PRIiLEAST64
273*16dce513Schristos # define PRIiLEAST64 PRIi64
274*16dce513Schristos #endif
275*16dce513Schristos #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
276*16dce513Schristos # undef PRIoLEAST64
277*16dce513Schristos # define PRIoLEAST64 PRIo64
278*16dce513Schristos #endif
279*16dce513Schristos #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
280*16dce513Schristos # undef PRIuLEAST64
281*16dce513Schristos # define PRIuLEAST64 PRIu64
282*16dce513Schristos #endif
283*16dce513Schristos #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
284*16dce513Schristos # undef PRIxLEAST64
285*16dce513Schristos # define PRIxLEAST64 PRIx64
286*16dce513Schristos #endif
287*16dce513Schristos #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
288*16dce513Schristos # undef PRIXLEAST64
289*16dce513Schristos # define PRIXLEAST64 PRIX64
290*16dce513Schristos #endif
291*16dce513Schristos #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
292*16dce513Schristos # undef PRIdFAST8
293*16dce513Schristos # define PRIdFAST8 "d"
294*16dce513Schristos #endif
295*16dce513Schristos #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
296*16dce513Schristos # undef PRIiFAST8
297*16dce513Schristos # define PRIiFAST8 "i"
298*16dce513Schristos #endif
299*16dce513Schristos #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
300*16dce513Schristos # undef PRIoFAST8
301*16dce513Schristos # define PRIoFAST8 "o"
302*16dce513Schristos #endif
303*16dce513Schristos #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
304*16dce513Schristos # undef PRIuFAST8
305*16dce513Schristos # define PRIuFAST8 "u"
306*16dce513Schristos #endif
307*16dce513Schristos #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
308*16dce513Schristos # undef PRIxFAST8
309*16dce513Schristos # define PRIxFAST8 "x"
310*16dce513Schristos #endif
311*16dce513Schristos #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
312*16dce513Schristos # undef PRIXFAST8
313*16dce513Schristos # define PRIXFAST8 "X"
314*16dce513Schristos #endif
315*16dce513Schristos #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
316*16dce513Schristos # undef PRIdFAST16
317*16dce513Schristos # define PRIdFAST16 "d"
318*16dce513Schristos #endif
319*16dce513Schristos #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
320*16dce513Schristos # undef PRIiFAST16
321*16dce513Schristos # define PRIiFAST16 "i"
322*16dce513Schristos #endif
323*16dce513Schristos #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
324*16dce513Schristos # undef PRIoFAST16
325*16dce513Schristos # define PRIoFAST16 "o"
326*16dce513Schristos #endif
327*16dce513Schristos #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
328*16dce513Schristos # undef PRIuFAST16
329*16dce513Schristos # define PRIuFAST16 "u"
330*16dce513Schristos #endif
331*16dce513Schristos #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
332*16dce513Schristos # undef PRIxFAST16
333*16dce513Schristos # define PRIxFAST16 "x"
334*16dce513Schristos #endif
335*16dce513Schristos #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
336*16dce513Schristos # undef PRIXFAST16
337*16dce513Schristos # define PRIXFAST16 "X"
338*16dce513Schristos #endif
339*16dce513Schristos #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
340*16dce513Schristos # undef PRIdFAST32
341*16dce513Schristos # define PRIdFAST32 "d"
342*16dce513Schristos #endif
343*16dce513Schristos #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
344*16dce513Schristos # undef PRIiFAST32
345*16dce513Schristos # define PRIiFAST32 "i"
346*16dce513Schristos #endif
347*16dce513Schristos #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
348*16dce513Schristos # undef PRIoFAST32
349*16dce513Schristos # define PRIoFAST32 "o"
350*16dce513Schristos #endif
351*16dce513Schristos #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
352*16dce513Schristos # undef PRIuFAST32
353*16dce513Schristos # define PRIuFAST32 "u"
354*16dce513Schristos #endif
355*16dce513Schristos #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
356*16dce513Schristos # undef PRIxFAST32
357*16dce513Schristos # define PRIxFAST32 "x"
358*16dce513Schristos #endif
359*16dce513Schristos #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
360*16dce513Schristos # undef PRIXFAST32
361*16dce513Schristos # define PRIXFAST32 "X"
362*16dce513Schristos #endif
363*16dce513Schristos #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
364*16dce513Schristos # undef PRIdFAST64
365*16dce513Schristos # define PRIdFAST64 PRId64
366*16dce513Schristos #endif
367*16dce513Schristos #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
368*16dce513Schristos # undef PRIiFAST64
369*16dce513Schristos # define PRIiFAST64 PRIi64
370*16dce513Schristos #endif
371*16dce513Schristos #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
372*16dce513Schristos # undef PRIoFAST64
373*16dce513Schristos # define PRIoFAST64 PRIo64
374*16dce513Schristos #endif
375*16dce513Schristos #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
376*16dce513Schristos # undef PRIuFAST64
377*16dce513Schristos # define PRIuFAST64 PRIu64
378*16dce513Schristos #endif
379*16dce513Schristos #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
380*16dce513Schristos # undef PRIxFAST64
381*16dce513Schristos # define PRIxFAST64 PRIx64
382*16dce513Schristos #endif
383*16dce513Schristos #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
384*16dce513Schristos # undef PRIXFAST64
385*16dce513Schristos # define PRIXFAST64 PRIX64
386*16dce513Schristos #endif
387*16dce513Schristos #if !defined PRIdMAX || PRI_MACROS_BROKEN
388*16dce513Schristos # undef PRIdMAX
389*16dce513Schristos # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
390*16dce513Schristos #endif
391*16dce513Schristos #if !defined PRIiMAX || PRI_MACROS_BROKEN
392*16dce513Schristos # undef PRIiMAX
393*16dce513Schristos # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
394*16dce513Schristos #endif
395*16dce513Schristos #if !defined PRIoMAX || PRI_MACROS_BROKEN
396*16dce513Schristos # undef PRIoMAX
397*16dce513Schristos # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
398*16dce513Schristos #endif
399*16dce513Schristos #if !defined PRIuMAX || PRI_MACROS_BROKEN
400*16dce513Schristos # undef PRIuMAX
401*16dce513Schristos # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
402*16dce513Schristos #endif
403*16dce513Schristos #if !defined PRIxMAX || PRI_MACROS_BROKEN
404*16dce513Schristos # undef PRIxMAX
405*16dce513Schristos # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
406*16dce513Schristos #endif
407*16dce513Schristos #if !defined PRIXMAX || PRI_MACROS_BROKEN
408*16dce513Schristos # undef PRIXMAX
409*16dce513Schristos # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
410*16dce513Schristos #endif
411*16dce513Schristos #if !defined PRIdPTR || PRI_MACROS_BROKEN
412*16dce513Schristos # undef PRIdPTR
413*16dce513Schristos # define PRIdPTR \
414*16dce513Schristos   (sizeof (void *) == sizeof (long) ? "ld" : \
415*16dce513Schristos    sizeof (void *) == sizeof (int) ? "d" : \
416*16dce513Schristos    "lld")
417*16dce513Schristos #endif
418*16dce513Schristos #if !defined PRIiPTR || PRI_MACROS_BROKEN
419*16dce513Schristos # undef PRIiPTR
420*16dce513Schristos # define PRIiPTR \
421*16dce513Schristos   (sizeof (void *) == sizeof (long) ? "li" : \
422*16dce513Schristos    sizeof (void *) == sizeof (int) ? "i" : \
423*16dce513Schristos    "lli")
424*16dce513Schristos #endif
425*16dce513Schristos #if !defined PRIoPTR || PRI_MACROS_BROKEN
426*16dce513Schristos # undef PRIoPTR
427*16dce513Schristos # define PRIoPTR \
428*16dce513Schristos   (sizeof (void *) == sizeof (long) ? "lo" : \
429*16dce513Schristos    sizeof (void *) == sizeof (int) ? "o" : \
430*16dce513Schristos    "llo")
431*16dce513Schristos #endif
432*16dce513Schristos #if !defined PRIuPTR || PRI_MACROS_BROKEN
433*16dce513Schristos # undef PRIuPTR
434*16dce513Schristos # define PRIuPTR \
435*16dce513Schristos   (sizeof (void *) == sizeof (long) ? "lu" : \
436*16dce513Schristos    sizeof (void *) == sizeof (int) ? "u" : \
437*16dce513Schristos    "llu")
438*16dce513Schristos #endif
439*16dce513Schristos #if !defined PRIxPTR || PRI_MACROS_BROKEN
440*16dce513Schristos # undef PRIxPTR
441*16dce513Schristos # define PRIxPTR \
442*16dce513Schristos   (sizeof (void *) == sizeof (long) ? "lx" : \
443*16dce513Schristos    sizeof (void *) == sizeof (int) ? "x" : \
444*16dce513Schristos    "llx")
445*16dce513Schristos #endif
446*16dce513Schristos #if !defined PRIXPTR || PRI_MACROS_BROKEN
447*16dce513Schristos # undef PRIXPTR
448*16dce513Schristos # define PRIXPTR \
449*16dce513Schristos   (sizeof (void *) == sizeof (long) ? "lX" : \
450*16dce513Schristos    sizeof (void *) == sizeof (int) ? "X" : \
451*16dce513Schristos    "llX")
452*16dce513Schristos #endif
453*16dce513Schristos 
454*16dce513Schristos /* @@ end of prolog @@ */
455*16dce513Schristos 
456*16dce513Schristos #ifdef _LIBC
457*16dce513Schristos /* Rename the non ISO C functions.  This is required by the standard
458*16dce513Schristos    because some ISO C functions will require linking with this object
459*16dce513Schristos    file and the name space must not be polluted.  */
460*16dce513Schristos # define open   __open
461*16dce513Schristos # define close  __close
462*16dce513Schristos # define read   __read
463*16dce513Schristos # define mmap   __mmap
464*16dce513Schristos # define munmap __munmap
465*16dce513Schristos #endif
466*16dce513Schristos 
467*16dce513Schristos /* For those losing systems which don't have `alloca' we have to add
468*16dce513Schristos    some additional code emulating it.  */
469*16dce513Schristos #ifdef HAVE_ALLOCA
470*16dce513Schristos # define freea(p) /* nothing */
471*16dce513Schristos #else
472*16dce513Schristos # define alloca(n) malloc (n)
473*16dce513Schristos # define freea(p) free (p)
474*16dce513Schristos #endif
475*16dce513Schristos 
476*16dce513Schristos /* For systems that distinguish between text and binary I/O.
477*16dce513Schristos    O_BINARY is usually declared in <fcntl.h>. */
478*16dce513Schristos #if !defined O_BINARY && defined _O_BINARY
479*16dce513Schristos   /* For MSC-compatible compilers.  */
480*16dce513Schristos # define O_BINARY _O_BINARY
481*16dce513Schristos # define O_TEXT _O_TEXT
482*16dce513Schristos #endif
483*16dce513Schristos #ifdef __BEOS__
484*16dce513Schristos   /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
485*16dce513Schristos # undef O_BINARY
486*16dce513Schristos # undef O_TEXT
487*16dce513Schristos #endif
488*16dce513Schristos /* On reasonable systems, binary I/O is the default.  */
489*16dce513Schristos #ifndef O_BINARY
490*16dce513Schristos # define O_BINARY 0
491*16dce513Schristos #endif
492*16dce513Schristos 
493*16dce513Schristos 
494*16dce513Schristos /* Prototypes for local functions.  Needed to ensure compiler checking of
495*16dce513Schristos    function argument counts despite of K&R C function definition syntax.  */
496*16dce513Schristos static const char *get_sysdep_segment_value PARAMS ((const char *name));
497*16dce513Schristos 
498*16dce513Schristos 
499*16dce513Schristos /* We need a sign, whether a new catalog was loaded, which can be associated
500*16dce513Schristos    with all translations.  This is important if the translations are
501*16dce513Schristos    cached by one of GCC's features.  */
502*16dce513Schristos int _nl_msg_cat_cntr;
503*16dce513Schristos 
504*16dce513Schristos 
505*16dce513Schristos /* Expand a system dependent string segment.  Return NULL if unsupported.  */
506*16dce513Schristos static const char *
get_sysdep_segment_value(name)507*16dce513Schristos get_sysdep_segment_value (name)
508*16dce513Schristos      const char *name;
509*16dce513Schristos {
510*16dce513Schristos   /* Test for an ISO C 99 section 7.8.1 format string directive.
511*16dce513Schristos      Syntax:
512*16dce513Schristos      P R I { d | i | o | u | x | X }
513*16dce513Schristos      { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR }  */
514*16dce513Schristos   /* We don't use a table of 14 times 6 'const char *' strings here, because
515*16dce513Schristos      data relocations cost startup time.  */
516*16dce513Schristos   if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I')
517*16dce513Schristos     {
518*16dce513Schristos       if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u'
519*16dce513Schristos 	  || name[3] == 'x' || name[3] == 'X')
520*16dce513Schristos 	{
521*16dce513Schristos 	  if (name[4] == '8' && name[5] == '\0')
522*16dce513Schristos 	    {
523*16dce513Schristos 	      if (name[3] == 'd')
524*16dce513Schristos 		return PRId8;
525*16dce513Schristos 	      if (name[3] == 'i')
526*16dce513Schristos 		return PRIi8;
527*16dce513Schristos 	      if (name[3] == 'o')
528*16dce513Schristos 		return PRIo8;
529*16dce513Schristos 	      if (name[3] == 'u')
530*16dce513Schristos 		return PRIu8;
531*16dce513Schristos 	      if (name[3] == 'x')
532*16dce513Schristos 		return PRIx8;
533*16dce513Schristos 	      if (name[3] == 'X')
534*16dce513Schristos 		return PRIX8;
535*16dce513Schristos 	      abort ();
536*16dce513Schristos 	    }
537*16dce513Schristos 	  if (name[4] == '1' && name[5] == '6' && name[6] == '\0')
538*16dce513Schristos 	    {
539*16dce513Schristos 	      if (name[3] == 'd')
540*16dce513Schristos 		return PRId16;
541*16dce513Schristos 	      if (name[3] == 'i')
542*16dce513Schristos 		return PRIi16;
543*16dce513Schristos 	      if (name[3] == 'o')
544*16dce513Schristos 		return PRIo16;
545*16dce513Schristos 	      if (name[3] == 'u')
546*16dce513Schristos 		return PRIu16;
547*16dce513Schristos 	      if (name[3] == 'x')
548*16dce513Schristos 		return PRIx16;
549*16dce513Schristos 	      if (name[3] == 'X')
550*16dce513Schristos 		return PRIX16;
551*16dce513Schristos 	      abort ();
552*16dce513Schristos 	    }
553*16dce513Schristos 	  if (name[4] == '3' && name[5] == '2' && name[6] == '\0')
554*16dce513Schristos 	    {
555*16dce513Schristos 	      if (name[3] == 'd')
556*16dce513Schristos 		return PRId32;
557*16dce513Schristos 	      if (name[3] == 'i')
558*16dce513Schristos 		return PRIi32;
559*16dce513Schristos 	      if (name[3] == 'o')
560*16dce513Schristos 		return PRIo32;
561*16dce513Schristos 	      if (name[3] == 'u')
562*16dce513Schristos 		return PRIu32;
563*16dce513Schristos 	      if (name[3] == 'x')
564*16dce513Schristos 		return PRIx32;
565*16dce513Schristos 	      if (name[3] == 'X')
566*16dce513Schristos 		return PRIX32;
567*16dce513Schristos 	      abort ();
568*16dce513Schristos 	    }
569*16dce513Schristos 	  if (name[4] == '6' && name[5] == '4' && name[6] == '\0')
570*16dce513Schristos 	    {
571*16dce513Schristos 	      if (name[3] == 'd')
572*16dce513Schristos 		return PRId64;
573*16dce513Schristos 	      if (name[3] == 'i')
574*16dce513Schristos 		return PRIi64;
575*16dce513Schristos 	      if (name[3] == 'o')
576*16dce513Schristos 		return PRIo64;
577*16dce513Schristos 	      if (name[3] == 'u')
578*16dce513Schristos 		return PRIu64;
579*16dce513Schristos 	      if (name[3] == 'x')
580*16dce513Schristos 		return PRIx64;
581*16dce513Schristos 	      if (name[3] == 'X')
582*16dce513Schristos 		return PRIX64;
583*16dce513Schristos 	      abort ();
584*16dce513Schristos 	    }
585*16dce513Schristos 	  if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A'
586*16dce513Schristos 	      && name[7] == 'S' && name[8] == 'T')
587*16dce513Schristos 	    {
588*16dce513Schristos 	      if (name[9] == '8' && name[10] == '\0')
589*16dce513Schristos 		{
590*16dce513Schristos 		  if (name[3] == 'd')
591*16dce513Schristos 		    return PRIdLEAST8;
592*16dce513Schristos 		  if (name[3] == 'i')
593*16dce513Schristos 		    return PRIiLEAST8;
594*16dce513Schristos 		  if (name[3] == 'o')
595*16dce513Schristos 		    return PRIoLEAST8;
596*16dce513Schristos 		  if (name[3] == 'u')
597*16dce513Schristos 		    return PRIuLEAST8;
598*16dce513Schristos 		  if (name[3] == 'x')
599*16dce513Schristos 		    return PRIxLEAST8;
600*16dce513Schristos 		  if (name[3] == 'X')
601*16dce513Schristos 		    return PRIXLEAST8;
602*16dce513Schristos 		  abort ();
603*16dce513Schristos 		}
604*16dce513Schristos 	      if (name[9] == '1' && name[10] == '6' && name[11] == '\0')
605*16dce513Schristos 		{
606*16dce513Schristos 		  if (name[3] == 'd')
607*16dce513Schristos 		    return PRIdLEAST16;
608*16dce513Schristos 		  if (name[3] == 'i')
609*16dce513Schristos 		    return PRIiLEAST16;
610*16dce513Schristos 		  if (name[3] == 'o')
611*16dce513Schristos 		    return PRIoLEAST16;
612*16dce513Schristos 		  if (name[3] == 'u')
613*16dce513Schristos 		    return PRIuLEAST16;
614*16dce513Schristos 		  if (name[3] == 'x')
615*16dce513Schristos 		    return PRIxLEAST16;
616*16dce513Schristos 		  if (name[3] == 'X')
617*16dce513Schristos 		    return PRIXLEAST16;
618*16dce513Schristos 		  abort ();
619*16dce513Schristos 		}
620*16dce513Schristos 	      if (name[9] == '3' && name[10] == '2' && name[11] == '\0')
621*16dce513Schristos 		{
622*16dce513Schristos 		  if (name[3] == 'd')
623*16dce513Schristos 		    return PRIdLEAST32;
624*16dce513Schristos 		  if (name[3] == 'i')
625*16dce513Schristos 		    return PRIiLEAST32;
626*16dce513Schristos 		  if (name[3] == 'o')
627*16dce513Schristos 		    return PRIoLEAST32;
628*16dce513Schristos 		  if (name[3] == 'u')
629*16dce513Schristos 		    return PRIuLEAST32;
630*16dce513Schristos 		  if (name[3] == 'x')
631*16dce513Schristos 		    return PRIxLEAST32;
632*16dce513Schristos 		  if (name[3] == 'X')
633*16dce513Schristos 		    return PRIXLEAST32;
634*16dce513Schristos 		  abort ();
635*16dce513Schristos 		}
636*16dce513Schristos 	      if (name[9] == '6' && name[10] == '4' && name[11] == '\0')
637*16dce513Schristos 		{
638*16dce513Schristos 		  if (name[3] == 'd')
639*16dce513Schristos 		    return PRIdLEAST64;
640*16dce513Schristos 		  if (name[3] == 'i')
641*16dce513Schristos 		    return PRIiLEAST64;
642*16dce513Schristos 		  if (name[3] == 'o')
643*16dce513Schristos 		    return PRIoLEAST64;
644*16dce513Schristos 		  if (name[3] == 'u')
645*16dce513Schristos 		    return PRIuLEAST64;
646*16dce513Schristos 		  if (name[3] == 'x')
647*16dce513Schristos 		    return PRIxLEAST64;
648*16dce513Schristos 		  if (name[3] == 'X')
649*16dce513Schristos 		    return PRIXLEAST64;
650*16dce513Schristos 		  abort ();
651*16dce513Schristos 		}
652*16dce513Schristos 	    }
653*16dce513Schristos 	  if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S'
654*16dce513Schristos 	      && name[7] == 'T')
655*16dce513Schristos 	    {
656*16dce513Schristos 	      if (name[8] == '8' && name[9] == '\0')
657*16dce513Schristos 		{
658*16dce513Schristos 		  if (name[3] == 'd')
659*16dce513Schristos 		    return PRIdFAST8;
660*16dce513Schristos 		  if (name[3] == 'i')
661*16dce513Schristos 		    return PRIiFAST8;
662*16dce513Schristos 		  if (name[3] == 'o')
663*16dce513Schristos 		    return PRIoFAST8;
664*16dce513Schristos 		  if (name[3] == 'u')
665*16dce513Schristos 		    return PRIuFAST8;
666*16dce513Schristos 		  if (name[3] == 'x')
667*16dce513Schristos 		    return PRIxFAST8;
668*16dce513Schristos 		  if (name[3] == 'X')
669*16dce513Schristos 		    return PRIXFAST8;
670*16dce513Schristos 		  abort ();
671*16dce513Schristos 		}
672*16dce513Schristos 	      if (name[8] == '1' && name[9] == '6' && name[10] == '\0')
673*16dce513Schristos 		{
674*16dce513Schristos 		  if (name[3] == 'd')
675*16dce513Schristos 		    return PRIdFAST16;
676*16dce513Schristos 		  if (name[3] == 'i')
677*16dce513Schristos 		    return PRIiFAST16;
678*16dce513Schristos 		  if (name[3] == 'o')
679*16dce513Schristos 		    return PRIoFAST16;
680*16dce513Schristos 		  if (name[3] == 'u')
681*16dce513Schristos 		    return PRIuFAST16;
682*16dce513Schristos 		  if (name[3] == 'x')
683*16dce513Schristos 		    return PRIxFAST16;
684*16dce513Schristos 		  if (name[3] == 'X')
685*16dce513Schristos 		    return PRIXFAST16;
686*16dce513Schristos 		  abort ();
687*16dce513Schristos 		}
688*16dce513Schristos 	      if (name[8] == '3' && name[9] == '2' && name[10] == '\0')
689*16dce513Schristos 		{
690*16dce513Schristos 		  if (name[3] == 'd')
691*16dce513Schristos 		    return PRIdFAST32;
692*16dce513Schristos 		  if (name[3] == 'i')
693*16dce513Schristos 		    return PRIiFAST32;
694*16dce513Schristos 		  if (name[3] == 'o')
695*16dce513Schristos 		    return PRIoFAST32;
696*16dce513Schristos 		  if (name[3] == 'u')
697*16dce513Schristos 		    return PRIuFAST32;
698*16dce513Schristos 		  if (name[3] == 'x')
699*16dce513Schristos 		    return PRIxFAST32;
700*16dce513Schristos 		  if (name[3] == 'X')
701*16dce513Schristos 		    return PRIXFAST32;
702*16dce513Schristos 		  abort ();
703*16dce513Schristos 		}
704*16dce513Schristos 	      if (name[8] == '6' && name[9] == '4' && name[10] == '\0')
705*16dce513Schristos 		{
706*16dce513Schristos 		  if (name[3] == 'd')
707*16dce513Schristos 		    return PRIdFAST64;
708*16dce513Schristos 		  if (name[3] == 'i')
709*16dce513Schristos 		    return PRIiFAST64;
710*16dce513Schristos 		  if (name[3] == 'o')
711*16dce513Schristos 		    return PRIoFAST64;
712*16dce513Schristos 		  if (name[3] == 'u')
713*16dce513Schristos 		    return PRIuFAST64;
714*16dce513Schristos 		  if (name[3] == 'x')
715*16dce513Schristos 		    return PRIxFAST64;
716*16dce513Schristos 		  if (name[3] == 'X')
717*16dce513Schristos 		    return PRIXFAST64;
718*16dce513Schristos 		  abort ();
719*16dce513Schristos 		}
720*16dce513Schristos 	    }
721*16dce513Schristos 	  if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X'
722*16dce513Schristos 	      && name[7] == '\0')
723*16dce513Schristos 	    {
724*16dce513Schristos 	      if (name[3] == 'd')
725*16dce513Schristos 		return PRIdMAX;
726*16dce513Schristos 	      if (name[3] == 'i')
727*16dce513Schristos 		return PRIiMAX;
728*16dce513Schristos 	      if (name[3] == 'o')
729*16dce513Schristos 		return PRIoMAX;
730*16dce513Schristos 	      if (name[3] == 'u')
731*16dce513Schristos 		return PRIuMAX;
732*16dce513Schristos 	      if (name[3] == 'x')
733*16dce513Schristos 		return PRIxMAX;
734*16dce513Schristos 	      if (name[3] == 'X')
735*16dce513Schristos 		return PRIXMAX;
736*16dce513Schristos 	      abort ();
737*16dce513Schristos 	    }
738*16dce513Schristos 	  if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R'
739*16dce513Schristos 	      && name[7] == '\0')
740*16dce513Schristos 	    {
741*16dce513Schristos 	      if (name[3] == 'd')
742*16dce513Schristos 		return PRIdPTR;
743*16dce513Schristos 	      if (name[3] == 'i')
744*16dce513Schristos 		return PRIiPTR;
745*16dce513Schristos 	      if (name[3] == 'o')
746*16dce513Schristos 		return PRIoPTR;
747*16dce513Schristos 	      if (name[3] == 'u')
748*16dce513Schristos 		return PRIuPTR;
749*16dce513Schristos 	      if (name[3] == 'x')
750*16dce513Schristos 		return PRIxPTR;
751*16dce513Schristos 	      if (name[3] == 'X')
752*16dce513Schristos 		return PRIXPTR;
753*16dce513Schristos 	      abort ();
754*16dce513Schristos 	    }
755*16dce513Schristos 	}
756*16dce513Schristos     }
757*16dce513Schristos   /* Other system dependent strings are not valid.  */
758*16dce513Schristos   return NULL;
759*16dce513Schristos }
760*16dce513Schristos 
761*16dce513Schristos /* Initialize the codeset dependent parts of an opened message catalog.
762*16dce513Schristos    Return the header entry.  */
763*16dce513Schristos const char *
764*16dce513Schristos internal_function
_nl_init_domain_conv(domain_file,domain,domainbinding)765*16dce513Schristos _nl_init_domain_conv (domain_file, domain, domainbinding)
766*16dce513Schristos      struct loaded_l10nfile *domain_file;
767*16dce513Schristos      struct loaded_domain *domain;
768*16dce513Schristos      struct binding *domainbinding;
769*16dce513Schristos {
770*16dce513Schristos   /* Find out about the character set the file is encoded with.
771*16dce513Schristos      This can be found (in textual form) in the entry "".  If this
772*16dce513Schristos      entry does not exist or if this does not contain the `charset='
773*16dce513Schristos      information, we will assume the charset matches the one the
774*16dce513Schristos      current locale and we don't have to perform any conversion.  */
775*16dce513Schristos   char *nullentry;
776*16dce513Schristos   size_t nullentrylen;
777*16dce513Schristos 
778*16dce513Schristos   /* Preinitialize fields, to avoid recursion during _nl_find_msg.  */
779*16dce513Schristos   domain->codeset_cntr =
780*16dce513Schristos     (domainbinding != NULL ? domainbinding->codeset_cntr : 0);
781*16dce513Schristos #ifdef _LIBC
782*16dce513Schristos   domain->conv = (__gconv_t) -1;
783*16dce513Schristos #else
784*16dce513Schristos # if HAVE_ICONV
785*16dce513Schristos   domain->conv = (iconv_t) -1;
786*16dce513Schristos # endif
787*16dce513Schristos #endif
788*16dce513Schristos   domain->conv_tab = NULL;
789*16dce513Schristos 
790*16dce513Schristos   /* Get the header entry.  */
791*16dce513Schristos   nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen);
792*16dce513Schristos 
793*16dce513Schristos   if (nullentry != NULL)
794*16dce513Schristos     {
795*16dce513Schristos #if defined _LIBC || HAVE_ICONV
796*16dce513Schristos       const char *charsetstr;
797*16dce513Schristos 
798*16dce513Schristos       charsetstr = strstr (nullentry, "charset=");
799*16dce513Schristos       if (charsetstr != NULL)
800*16dce513Schristos 	{
801*16dce513Schristos 	  size_t len;
802*16dce513Schristos 	  char *charset;
803*16dce513Schristos 	  const char *outcharset;
804*16dce513Schristos 
805*16dce513Schristos 	  charsetstr += strlen ("charset=");
806*16dce513Schristos 	  len = strcspn (charsetstr, " \t\n");
807*16dce513Schristos 
808*16dce513Schristos 	  charset = (char *) alloca (len + 1);
809*16dce513Schristos # if defined _LIBC || HAVE_MEMPCPY
810*16dce513Schristos 	  *((char *) mempcpy (charset, charsetstr, len)) = '\0';
811*16dce513Schristos # else
812*16dce513Schristos 	  memcpy (charset, charsetstr, len);
813*16dce513Schristos 	  charset[len] = '\0';
814*16dce513Schristos # endif
815*16dce513Schristos 
816*16dce513Schristos 	  /* The output charset should normally be determined by the
817*16dce513Schristos 	     locale.  But sometimes the locale is not used or not correctly
818*16dce513Schristos 	     set up, so we provide a possibility for the user to override
819*16dce513Schristos 	     this.  Moreover, the value specified through
820*16dce513Schristos 	     bind_textdomain_codeset overrides both.  */
821*16dce513Schristos 	  if (domainbinding != NULL && domainbinding->codeset != NULL)
822*16dce513Schristos 	    outcharset = domainbinding->codeset;
823*16dce513Schristos 	  else
824*16dce513Schristos 	    {
825*16dce513Schristos 	      outcharset = getenv ("OUTPUT_CHARSET");
826*16dce513Schristos 	      if (outcharset == NULL || outcharset[0] == '\0')
827*16dce513Schristos 		{
828*16dce513Schristos # ifdef _LIBC
829*16dce513Schristos 		  outcharset = _NL_CURRENT (LC_CTYPE, CODESET);
830*16dce513Schristos # else
831*16dce513Schristos #  if HAVE_ICONV
832*16dce513Schristos 		  extern const char *locale_charset PARAMS ((void));
833*16dce513Schristos 		  outcharset = locale_charset ();
834*16dce513Schristos #  endif
835*16dce513Schristos # endif
836*16dce513Schristos 		}
837*16dce513Schristos 	    }
838*16dce513Schristos 
839*16dce513Schristos # ifdef _LIBC
840*16dce513Schristos 	  /* We always want to use transliteration.  */
841*16dce513Schristos 	  outcharset = norm_add_slashes (outcharset, "TRANSLIT");
842*16dce513Schristos 	  charset = norm_add_slashes (charset, NULL);
843*16dce513Schristos 	  if (__gconv_open (outcharset, charset, &domain->conv,
844*16dce513Schristos 			    GCONV_AVOID_NOCONV)
845*16dce513Schristos 	      != __GCONV_OK)
846*16dce513Schristos 	    domain->conv = (__gconv_t) -1;
847*16dce513Schristos # else
848*16dce513Schristos #  if HAVE_ICONV
849*16dce513Schristos 	  /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
850*16dce513Schristos 	     we want to use transliteration.  */
851*16dce513Schristos #   if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
852*16dce513Schristos        || _LIBICONV_VERSION >= 0x0105
853*16dce513Schristos 	  if (strchr (outcharset, '/') == NULL)
854*16dce513Schristos 	    {
855*16dce513Schristos 	      char *tmp;
856*16dce513Schristos 
857*16dce513Schristos 	      len = strlen (outcharset);
858*16dce513Schristos 	      tmp = (char *) alloca (len + 10 + 1);
859*16dce513Schristos 	      memcpy (tmp, outcharset, len);
860*16dce513Schristos 	      memcpy (tmp + len, "//TRANSLIT", 10 + 1);
861*16dce513Schristos 	      outcharset = tmp;
862*16dce513Schristos 
863*16dce513Schristos 	      domain->conv = iconv_open (outcharset, charset);
864*16dce513Schristos 
865*16dce513Schristos 	      freea (outcharset);
866*16dce513Schristos 	    }
867*16dce513Schristos 	  else
868*16dce513Schristos #   endif
869*16dce513Schristos 	    domain->conv = iconv_open (outcharset, charset);
870*16dce513Schristos #  endif
871*16dce513Schristos # endif
872*16dce513Schristos 
873*16dce513Schristos 	  freea (charset);
874*16dce513Schristos 	}
875*16dce513Schristos #endif /* _LIBC || HAVE_ICONV */
876*16dce513Schristos     }
877*16dce513Schristos 
878*16dce513Schristos   return nullentry;
879*16dce513Schristos }
880*16dce513Schristos 
881*16dce513Schristos /* Frees the codeset dependent parts of an opened message catalog.  */
882*16dce513Schristos void
883*16dce513Schristos internal_function
_nl_free_domain_conv(domain)884*16dce513Schristos _nl_free_domain_conv (domain)
885*16dce513Schristos      struct loaded_domain *domain;
886*16dce513Schristos {
887*16dce513Schristos   if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1)
888*16dce513Schristos     free (domain->conv_tab);
889*16dce513Schristos 
890*16dce513Schristos #ifdef _LIBC
891*16dce513Schristos   if (domain->conv != (__gconv_t) -1)
892*16dce513Schristos     __gconv_close (domain->conv);
893*16dce513Schristos #else
894*16dce513Schristos # if HAVE_ICONV
895*16dce513Schristos   if (domain->conv != (iconv_t) -1)
896*16dce513Schristos     iconv_close (domain->conv);
897*16dce513Schristos # endif
898*16dce513Schristos #endif
899*16dce513Schristos }
900*16dce513Schristos 
901*16dce513Schristos /* Load the message catalogs specified by FILENAME.  If it is no valid
902*16dce513Schristos    message catalog do nothing.  */
903*16dce513Schristos void
904*16dce513Schristos internal_function
_nl_load_domain(domain_file,domainbinding)905*16dce513Schristos _nl_load_domain (domain_file, domainbinding)
906*16dce513Schristos      struct loaded_l10nfile *domain_file;
907*16dce513Schristos      struct binding *domainbinding;
908*16dce513Schristos {
909*16dce513Schristos   int fd;
910*16dce513Schristos   size_t size;
911*16dce513Schristos #ifdef _LIBC
912*16dce513Schristos   struct stat64 st;
913*16dce513Schristos #else
914*16dce513Schristos   struct stat st;
915*16dce513Schristos #endif
916*16dce513Schristos   struct mo_file_header *data = (struct mo_file_header *) -1;
917*16dce513Schristos   int use_mmap = 0;
918*16dce513Schristos   struct loaded_domain *domain;
919*16dce513Schristos   int revision;
920*16dce513Schristos   const char *nullentry;
921*16dce513Schristos 
922*16dce513Schristos   domain_file->decided = 1;
923*16dce513Schristos   domain_file->data = NULL;
924*16dce513Schristos 
925*16dce513Schristos   /* Note that it would be useless to store domainbinding in domain_file
926*16dce513Schristos      because domainbinding might be == NULL now but != NULL later (after
927*16dce513Schristos      a call to bind_textdomain_codeset).  */
928*16dce513Schristos 
929*16dce513Schristos   /* If the record does not represent a valid locale the FILENAME
930*16dce513Schristos      might be NULL.  This can happen when according to the given
931*16dce513Schristos      specification the locale file name is different for XPG and CEN
932*16dce513Schristos      syntax.  */
933*16dce513Schristos   if (domain_file->filename == NULL)
934*16dce513Schristos     return;
935*16dce513Schristos 
936*16dce513Schristos   /* Try to open the addressed file.  */
937*16dce513Schristos   fd = open (domain_file->filename, O_RDONLY | O_BINARY);
938*16dce513Schristos   if (fd == -1)
939*16dce513Schristos     return;
940*16dce513Schristos 
941*16dce513Schristos   /* We must know about the size of the file.  */
942*16dce513Schristos   if (
943*16dce513Schristos #ifdef _LIBC
944*16dce513Schristos       __builtin_expect (fstat64 (fd, &st) != 0, 0)
945*16dce513Schristos #else
946*16dce513Schristos       __builtin_expect (fstat (fd, &st) != 0, 0)
947*16dce513Schristos #endif
948*16dce513Schristos       || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
949*16dce513Schristos       || __builtin_expect (size < sizeof (struct mo_file_header), 0))
950*16dce513Schristos     {
951*16dce513Schristos       /* Something went wrong.  */
952*16dce513Schristos       close (fd);
953*16dce513Schristos       return;
954*16dce513Schristos     }
955*16dce513Schristos 
956*16dce513Schristos #ifdef HAVE_MMAP
957*16dce513Schristos   /* Now we are ready to load the file.  If mmap() is available we try
958*16dce513Schristos      this first.  If not available or it failed we try to load it.  */
959*16dce513Schristos   data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
960*16dce513Schristos 					 MAP_PRIVATE, fd, 0);
961*16dce513Schristos 
962*16dce513Schristos   if (__builtin_expect (data != (struct mo_file_header *) -1, 1))
963*16dce513Schristos     {
964*16dce513Schristos       /* mmap() call was successful.  */
965*16dce513Schristos       close (fd);
966*16dce513Schristos       use_mmap = 1;
967*16dce513Schristos     }
968*16dce513Schristos #endif
969*16dce513Schristos 
970*16dce513Schristos   /* If the data is not yet available (i.e. mmap'ed) we try to load
971*16dce513Schristos      it manually.  */
972*16dce513Schristos   if (data == (struct mo_file_header *) -1)
973*16dce513Schristos     {
974*16dce513Schristos       size_t to_read;
975*16dce513Schristos       char *read_ptr;
976*16dce513Schristos 
977*16dce513Schristos       data = (struct mo_file_header *) malloc (size);
978*16dce513Schristos       if (data == NULL)
979*16dce513Schristos 	return;
980*16dce513Schristos 
981*16dce513Schristos       to_read = size;
982*16dce513Schristos       read_ptr = (char *) data;
983*16dce513Schristos       do
984*16dce513Schristos 	{
985*16dce513Schristos 	  long int nb = (long int) read (fd, read_ptr, to_read);
986*16dce513Schristos 	  if (nb <= 0)
987*16dce513Schristos 	    {
988*16dce513Schristos #ifdef EINTR
989*16dce513Schristos 	      if (nb == -1 && errno == EINTR)
990*16dce513Schristos 		continue;
991*16dce513Schristos #endif
992*16dce513Schristos 	      close (fd);
993*16dce513Schristos 	      return;
994*16dce513Schristos 	    }
995*16dce513Schristos 	  read_ptr += nb;
996*16dce513Schristos 	  to_read -= nb;
997*16dce513Schristos 	}
998*16dce513Schristos       while (to_read > 0);
999*16dce513Schristos 
1000*16dce513Schristos       close (fd);
1001*16dce513Schristos     }
1002*16dce513Schristos 
1003*16dce513Schristos   /* Using the magic number we can test whether it really is a message
1004*16dce513Schristos      catalog file.  */
1005*16dce513Schristos   if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED,
1006*16dce513Schristos 			0))
1007*16dce513Schristos     {
1008*16dce513Schristos       /* The magic number is wrong: not a message catalog file.  */
1009*16dce513Schristos #ifdef HAVE_MMAP
1010*16dce513Schristos       if (use_mmap)
1011*16dce513Schristos 	munmap ((caddr_t) data, size);
1012*16dce513Schristos       else
1013*16dce513Schristos #endif
1014*16dce513Schristos 	free (data);
1015*16dce513Schristos       return;
1016*16dce513Schristos     }
1017*16dce513Schristos 
1018*16dce513Schristos   domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
1019*16dce513Schristos   if (domain == NULL)
1020*16dce513Schristos     return;
1021*16dce513Schristos   domain_file->data = domain;
1022*16dce513Schristos 
1023*16dce513Schristos   domain->data = (char *) data;
1024*16dce513Schristos   domain->use_mmap = use_mmap;
1025*16dce513Schristos   domain->mmap_size = size;
1026*16dce513Schristos   domain->must_swap = data->magic != _MAGIC;
1027*16dce513Schristos   domain->malloced = NULL;
1028*16dce513Schristos 
1029*16dce513Schristos   /* Fill in the information about the available tables.  */
1030*16dce513Schristos   revision = W (domain->must_swap, data->revision);
1031*16dce513Schristos   /* We support only the major revision 0.  */
1032*16dce513Schristos   switch (revision >> 16)
1033*16dce513Schristos     {
1034*16dce513Schristos     case 0:
1035*16dce513Schristos       domain->nstrings = W (domain->must_swap, data->nstrings);
1036*16dce513Schristos       domain->orig_tab = (const struct string_desc *)
1037*16dce513Schristos 	((char *) data + W (domain->must_swap, data->orig_tab_offset));
1038*16dce513Schristos       domain->trans_tab = (const struct string_desc *)
1039*16dce513Schristos 	((char *) data + W (domain->must_swap, data->trans_tab_offset));
1040*16dce513Schristos       domain->hash_size = W (domain->must_swap, data->hash_tab_size);
1041*16dce513Schristos       domain->hash_tab =
1042*16dce513Schristos 	(domain->hash_size > 2
1043*16dce513Schristos 	 ? (const nls_uint32 *)
1044*16dce513Schristos 	   ((char *) data + W (domain->must_swap, data->hash_tab_offset))
1045*16dce513Schristos 	 : NULL);
1046*16dce513Schristos       domain->must_swap_hash_tab = domain->must_swap;
1047*16dce513Schristos 
1048*16dce513Schristos       /* Now dispatch on the minor revision.  */
1049*16dce513Schristos       switch (revision & 0xffff)
1050*16dce513Schristos 	{
1051*16dce513Schristos 	case 0:
1052*16dce513Schristos 	  domain->n_sysdep_strings = 0;
1053*16dce513Schristos 	  domain->orig_sysdep_tab = NULL;
1054*16dce513Schristos 	  domain->trans_sysdep_tab = NULL;
1055*16dce513Schristos 	  break;
1056*16dce513Schristos 	case 1:
1057*16dce513Schristos 	default:
1058*16dce513Schristos 	  {
1059*16dce513Schristos 	    nls_uint32 n_sysdep_strings;
1060*16dce513Schristos 
1061*16dce513Schristos 	    if (domain->hash_tab == NULL)
1062*16dce513Schristos 	      /* This is invalid.  These minor revisions need a hash table.  */
1063*16dce513Schristos 	      goto invalid;
1064*16dce513Schristos 
1065*16dce513Schristos 	    n_sysdep_strings =
1066*16dce513Schristos 	      W (domain->must_swap, data->n_sysdep_strings);
1067*16dce513Schristos 	    if (n_sysdep_strings > 0)
1068*16dce513Schristos 	      {
1069*16dce513Schristos 		nls_uint32 n_sysdep_segments;
1070*16dce513Schristos 		const struct sysdep_segment *sysdep_segments;
1071*16dce513Schristos 		const char **sysdep_segment_values;
1072*16dce513Schristos 		const nls_uint32 *orig_sysdep_tab;
1073*16dce513Schristos 		const nls_uint32 *trans_sysdep_tab;
1074*16dce513Schristos 		size_t memneed;
1075*16dce513Schristos 		char *mem;
1076*16dce513Schristos 		struct sysdep_string_desc *inmem_orig_sysdep_tab;
1077*16dce513Schristos 		struct sysdep_string_desc *inmem_trans_sysdep_tab;
1078*16dce513Schristos 		nls_uint32 *inmem_hash_tab;
1079*16dce513Schristos 		unsigned int i;
1080*16dce513Schristos 
1081*16dce513Schristos 		/* Get the values of the system dependent segments.  */
1082*16dce513Schristos 		n_sysdep_segments =
1083*16dce513Schristos 		  W (domain->must_swap, data->n_sysdep_segments);
1084*16dce513Schristos 		sysdep_segments = (const struct sysdep_segment *)
1085*16dce513Schristos 		  ((char *) data
1086*16dce513Schristos 		   + W (domain->must_swap, data->sysdep_segments_offset));
1087*16dce513Schristos 		sysdep_segment_values =
1088*16dce513Schristos 		  alloca (n_sysdep_segments * sizeof (const char *));
1089*16dce513Schristos 		for (i = 0; i < n_sysdep_segments; i++)
1090*16dce513Schristos 		  {
1091*16dce513Schristos 		    const char *name =
1092*16dce513Schristos 		      (char *) data
1093*16dce513Schristos 		      + W (domain->must_swap, sysdep_segments[i].offset);
1094*16dce513Schristos 		    nls_uint32 namelen =
1095*16dce513Schristos 		      W (domain->must_swap, sysdep_segments[i].length);
1096*16dce513Schristos 
1097*16dce513Schristos 		    if (!(namelen > 0 && name[namelen - 1] == '\0'))
1098*16dce513Schristos 		      {
1099*16dce513Schristos 			freea (sysdep_segment_values);
1100*16dce513Schristos 			goto invalid;
1101*16dce513Schristos 		      }
1102*16dce513Schristos 
1103*16dce513Schristos 		    sysdep_segment_values[i] = get_sysdep_segment_value (name);
1104*16dce513Schristos 		  }
1105*16dce513Schristos 
1106*16dce513Schristos 		orig_sysdep_tab = (const nls_uint32 *)
1107*16dce513Schristos 		  ((char *) data
1108*16dce513Schristos 		   + W (domain->must_swap, data->orig_sysdep_tab_offset));
1109*16dce513Schristos 		trans_sysdep_tab = (const nls_uint32 *)
1110*16dce513Schristos 		  ((char *) data
1111*16dce513Schristos 		   + W (domain->must_swap, data->trans_sysdep_tab_offset));
1112*16dce513Schristos 
1113*16dce513Schristos 		/* Compute the amount of additional memory needed for the
1114*16dce513Schristos 		   system dependent strings and the augmented hash table.  */
1115*16dce513Schristos 		memneed = 2 * n_sysdep_strings
1116*16dce513Schristos 			  * sizeof (struct sysdep_string_desc)
1117*16dce513Schristos 			  + domain->hash_size * sizeof (nls_uint32);
1118*16dce513Schristos 		for (i = 0; i < 2 * n_sysdep_strings; i++)
1119*16dce513Schristos 		  {
1120*16dce513Schristos 		    const struct sysdep_string *sysdep_string =
1121*16dce513Schristos 		      (const struct sysdep_string *)
1122*16dce513Schristos 		      ((char *) data
1123*16dce513Schristos 		       + W (domain->must_swap,
1124*16dce513Schristos 			    i < n_sysdep_strings
1125*16dce513Schristos 			    ? orig_sysdep_tab[i]
1126*16dce513Schristos 			    : trans_sysdep_tab[i - n_sysdep_strings]));
1127*16dce513Schristos 		    size_t need = 0;
1128*16dce513Schristos 		    const struct segment_pair *p = sysdep_string->segments;
1129*16dce513Schristos 
1130*16dce513Schristos 		    if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END)
1131*16dce513Schristos 		      for (p = sysdep_string->segments;; p++)
1132*16dce513Schristos 			{
1133*16dce513Schristos 			  nls_uint32 sysdepref;
1134*16dce513Schristos 
1135*16dce513Schristos 			  need += W (domain->must_swap, p->segsize);
1136*16dce513Schristos 
1137*16dce513Schristos 			  sysdepref = W (domain->must_swap, p->sysdepref);
1138*16dce513Schristos 			  if (sysdepref == SEGMENTS_END)
1139*16dce513Schristos 			    break;
1140*16dce513Schristos 
1141*16dce513Schristos 			  if (sysdepref >= n_sysdep_segments)
1142*16dce513Schristos 			    {
1143*16dce513Schristos 			      /* Invalid.  */
1144*16dce513Schristos 			      freea (sysdep_segment_values);
1145*16dce513Schristos 			      goto invalid;
1146*16dce513Schristos 			    }
1147*16dce513Schristos 
1148*16dce513Schristos 			  need += strlen (sysdep_segment_values[sysdepref]);
1149*16dce513Schristos 			}
1150*16dce513Schristos 
1151*16dce513Schristos 		    memneed += need;
1152*16dce513Schristos 		  }
1153*16dce513Schristos 
1154*16dce513Schristos 		/* Allocate additional memory.  */
1155*16dce513Schristos 		mem = (char *) malloc (memneed);
1156*16dce513Schristos 		if (mem == NULL)
1157*16dce513Schristos 		  goto invalid;
1158*16dce513Schristos 
1159*16dce513Schristos 		domain->malloced = mem;
1160*16dce513Schristos 		inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem;
1161*16dce513Schristos 		mem += n_sysdep_strings * sizeof (struct sysdep_string_desc);
1162*16dce513Schristos 		inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem;
1163*16dce513Schristos 		mem += n_sysdep_strings * sizeof (struct sysdep_string_desc);
1164*16dce513Schristos 		inmem_hash_tab = (nls_uint32 *) mem;
1165*16dce513Schristos 		mem += domain->hash_size * sizeof (nls_uint32);
1166*16dce513Schristos 
1167*16dce513Schristos 		/* Compute the system dependent strings.  */
1168*16dce513Schristos 		for (i = 0; i < 2 * n_sysdep_strings; i++)
1169*16dce513Schristos 		  {
1170*16dce513Schristos 		    const struct sysdep_string *sysdep_string =
1171*16dce513Schristos 		      (const struct sysdep_string *)
1172*16dce513Schristos 		      ((char *) data
1173*16dce513Schristos 		       + W (domain->must_swap,
1174*16dce513Schristos 			    i < n_sysdep_strings
1175*16dce513Schristos 			    ? orig_sysdep_tab[i]
1176*16dce513Schristos 			    : trans_sysdep_tab[i - n_sysdep_strings]));
1177*16dce513Schristos 		    const char *static_segments =
1178*16dce513Schristos 		      (char *) data
1179*16dce513Schristos 		      + W (domain->must_swap, sysdep_string->offset);
1180*16dce513Schristos 		    const struct segment_pair *p = sysdep_string->segments;
1181*16dce513Schristos 
1182*16dce513Schristos 		    /* Concatenate the segments, and fill
1183*16dce513Schristos 		       inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and
1184*16dce513Schristos 		       inmem_trans_sysdep_tab[i-n_sysdep_strings] (for
1185*16dce513Schristos 		       i >= n_sysdep_strings).  */
1186*16dce513Schristos 
1187*16dce513Schristos 		    if (W (domain->must_swap, p->sysdepref) == SEGMENTS_END)
1188*16dce513Schristos 		      {
1189*16dce513Schristos 			/* Only one static segment.  */
1190*16dce513Schristos 			inmem_orig_sysdep_tab[i].length =
1191*16dce513Schristos 			  W (domain->must_swap, p->segsize);
1192*16dce513Schristos 			inmem_orig_sysdep_tab[i].pointer = static_segments;
1193*16dce513Schristos 		      }
1194*16dce513Schristos 		    else
1195*16dce513Schristos 		      {
1196*16dce513Schristos 			inmem_orig_sysdep_tab[i].pointer = mem;
1197*16dce513Schristos 
1198*16dce513Schristos 			for (p = sysdep_string->segments;; p++)
1199*16dce513Schristos 			  {
1200*16dce513Schristos 			    nls_uint32 segsize =
1201*16dce513Schristos 			      W (domain->must_swap, p->segsize);
1202*16dce513Schristos 			    nls_uint32 sysdepref =
1203*16dce513Schristos 			      W (domain->must_swap, p->sysdepref);
1204*16dce513Schristos 			    size_t n;
1205*16dce513Schristos 
1206*16dce513Schristos 			    if (segsize > 0)
1207*16dce513Schristos 			      {
1208*16dce513Schristos 				memcpy (mem, static_segments, segsize);
1209*16dce513Schristos 				mem += segsize;
1210*16dce513Schristos 				static_segments += segsize;
1211*16dce513Schristos 			      }
1212*16dce513Schristos 
1213*16dce513Schristos 			    if (sysdepref == SEGMENTS_END)
1214*16dce513Schristos 			      break;
1215*16dce513Schristos 
1216*16dce513Schristos 			    n = strlen (sysdep_segment_values[sysdepref]);
1217*16dce513Schristos 			    memcpy (mem, sysdep_segment_values[sysdepref], n);
1218*16dce513Schristos 			    mem += n;
1219*16dce513Schristos 			  }
1220*16dce513Schristos 
1221*16dce513Schristos 			inmem_orig_sysdep_tab[i].length =
1222*16dce513Schristos 			  mem - inmem_orig_sysdep_tab[i].pointer;
1223*16dce513Schristos 		      }
1224*16dce513Schristos 		  }
1225*16dce513Schristos 
1226*16dce513Schristos 		/* Compute the augmented hash table.  */
1227*16dce513Schristos 		for (i = 0; i < domain->hash_size; i++)
1228*16dce513Schristos 		  inmem_hash_tab[i] =
1229*16dce513Schristos 		    W (domain->must_swap_hash_tab, domain->hash_tab[i]);
1230*16dce513Schristos 		for (i = 0; i < n_sysdep_strings; i++)
1231*16dce513Schristos 		  {
1232*16dce513Schristos 		    const char *msgid = inmem_orig_sysdep_tab[i].pointer;
1233*16dce513Schristos 		    nls_uint32 hash_val = hash_string (msgid);
1234*16dce513Schristos 		    nls_uint32 idx = hash_val % domain->hash_size;
1235*16dce513Schristos 		    nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2));
1236*16dce513Schristos 
1237*16dce513Schristos 		    for (;;)
1238*16dce513Schristos 		      {
1239*16dce513Schristos 			if (inmem_hash_tab[idx] == 0)
1240*16dce513Schristos 			  {
1241*16dce513Schristos 			    /* Hash table entry is empty.  Use it.  */
1242*16dce513Schristos 			    inmem_hash_tab[idx] = 1 + domain->nstrings + i;
1243*16dce513Schristos 			    break;
1244*16dce513Schristos 			  }
1245*16dce513Schristos 
1246*16dce513Schristos 			if (idx >= domain->hash_size - incr)
1247*16dce513Schristos 			  idx -= domain->hash_size - incr;
1248*16dce513Schristos 			else
1249*16dce513Schristos 			  idx += incr;
1250*16dce513Schristos 		      }
1251*16dce513Schristos 		  }
1252*16dce513Schristos 
1253*16dce513Schristos 		freea (sysdep_segment_values);
1254*16dce513Schristos 
1255*16dce513Schristos 		domain->n_sysdep_strings = n_sysdep_strings;
1256*16dce513Schristos 		domain->orig_sysdep_tab = inmem_orig_sysdep_tab;
1257*16dce513Schristos 		domain->trans_sysdep_tab = inmem_trans_sysdep_tab;
1258*16dce513Schristos 
1259*16dce513Schristos 		domain->hash_tab = inmem_hash_tab;
1260*16dce513Schristos 		domain->must_swap_hash_tab = 0;
1261*16dce513Schristos 	      }
1262*16dce513Schristos 	    else
1263*16dce513Schristos 	      {
1264*16dce513Schristos 		domain->n_sysdep_strings = 0;
1265*16dce513Schristos 		domain->orig_sysdep_tab = NULL;
1266*16dce513Schristos 		domain->trans_sysdep_tab = NULL;
1267*16dce513Schristos 	      }
1268*16dce513Schristos 	  }
1269*16dce513Schristos 	  break;
1270*16dce513Schristos 	}
1271*16dce513Schristos       break;
1272*16dce513Schristos     default:
1273*16dce513Schristos       /* This is an invalid revision.  */
1274*16dce513Schristos     invalid:
1275*16dce513Schristos       /* This is an invalid .mo file.  */
1276*16dce513Schristos       if (domain->malloced)
1277*16dce513Schristos 	free (domain->malloced);
1278*16dce513Schristos #ifdef HAVE_MMAP
1279*16dce513Schristos       if (use_mmap)
1280*16dce513Schristos 	munmap ((caddr_t) data, size);
1281*16dce513Schristos       else
1282*16dce513Schristos #endif
1283*16dce513Schristos 	free (data);
1284*16dce513Schristos       free (domain);
1285*16dce513Schristos       domain_file->data = NULL;
1286*16dce513Schristos       return;
1287*16dce513Schristos     }
1288*16dce513Schristos 
1289*16dce513Schristos   /* Now initialize the character set converter from the character set
1290*16dce513Schristos      the file is encoded with (found in the header entry) to the domain's
1291*16dce513Schristos      specified character set or the locale's character set.  */
1292*16dce513Schristos   nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding);
1293*16dce513Schristos 
1294*16dce513Schristos   /* Also look for a plural specification.  */
1295*16dce513Schristos   EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals);
1296*16dce513Schristos }
1297*16dce513Schristos 
1298*16dce513Schristos 
1299*16dce513Schristos #ifdef _LIBC
1300*16dce513Schristos void
1301*16dce513Schristos internal_function
_nl_unload_domain(domain)1302*16dce513Schristos _nl_unload_domain (domain)
1303*16dce513Schristos      struct loaded_domain *domain;
1304*16dce513Schristos {
1305*16dce513Schristos   if (domain->plural != &__gettext_germanic_plural)
1306*16dce513Schristos     __gettext_free_exp (domain->plural);
1307*16dce513Schristos 
1308*16dce513Schristos   _nl_free_domain_conv (domain);
1309*16dce513Schristos 
1310*16dce513Schristos   if (domain->malloced)
1311*16dce513Schristos     free (domain->malloced);
1312*16dce513Schristos 
1313*16dce513Schristos # ifdef _POSIX_MAPPED_FILES
1314*16dce513Schristos   if (domain->use_mmap)
1315*16dce513Schristos     munmap ((caddr_t) domain->data, domain->mmap_size);
1316*16dce513Schristos   else
1317*16dce513Schristos # endif	/* _POSIX_MAPPED_FILES */
1318*16dce513Schristos     free ((void *) domain->data);
1319*16dce513Schristos 
1320*16dce513Schristos   free (domain);
1321*16dce513Schristos }
1322*16dce513Schristos #endif
1323