xref: /openbsd-src/gnu/usr.bin/texinfo/intl/loadmsgcat.c (revision a1acfa9b69ad64eb720639240c8438f11107dc85)
11cc83814Sespie /* Load needed message catalogs.
2*a1acfa9bSespie    Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc.
3840175f0Skstailey 
43fb98d4aSespie    This program is free software; you can redistribute it and/or modify it
53fb98d4aSespie    under the terms of the GNU Library General Public License as published
63fb98d4aSespie    by the Free Software Foundation; either version 2, or (at your option)
7840175f0Skstailey    any later version.
8840175f0Skstailey 
9840175f0Skstailey    This program is distributed in the hope that it will be useful,
10840175f0Skstailey    but WITHOUT ANY WARRANTY; without even the implied warranty of
113fb98d4aSespie    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
123fb98d4aSespie    Library General Public License for more details.
13840175f0Skstailey 
143fb98d4aSespie    You should have received a copy of the GNU Library General Public
153fb98d4aSespie    License along with this program; if not, write to the Free Software
163fb98d4aSespie    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
173fb98d4aSespie    USA.  */
183fb98d4aSespie 
193fb98d4aSespie /* Tell glibc's <string.h> to provide a prototype for mempcpy().
203fb98d4aSespie    This must come before <config.h> because <config.h> may include
213fb98d4aSespie    <features.h>, and once <features.h> has been included, it's too late.  */
223fb98d4aSespie #ifndef _GNU_SOURCE
233fb98d4aSespie # define _GNU_SOURCE    1
243fb98d4aSespie #endif
25840175f0Skstailey 
26840175f0Skstailey #ifdef HAVE_CONFIG_H
27840175f0Skstailey # include <config.h>
28840175f0Skstailey #endif
29840175f0Skstailey 
303fb98d4aSespie #include <ctype.h>
313fb98d4aSespie #include <errno.h>
32840175f0Skstailey #include <fcntl.h>
33840175f0Skstailey #include <sys/types.h>
34840175f0Skstailey #include <sys/stat.h>
35840175f0Skstailey 
363fb98d4aSespie #ifdef __GNUC__
37*a1acfa9bSespie # undef  alloca
383fb98d4aSespie # define alloca __builtin_alloca
393fb98d4aSespie # define HAVE_ALLOCA 1
403fb98d4aSespie #else
41*a1acfa9bSespie # ifdef _MSC_VER
42*a1acfa9bSespie #  include <malloc.h>
43*a1acfa9bSespie #  define alloca _alloca
44*a1acfa9bSespie # else
453fb98d4aSespie #  if defined HAVE_ALLOCA_H || defined _LIBC
463fb98d4aSespie #   include <alloca.h>
473fb98d4aSespie #  else
483fb98d4aSespie #   ifdef _AIX
493fb98d4aSespie  #pragma alloca
503fb98d4aSespie #   else
513fb98d4aSespie #    ifndef alloca
523fb98d4aSespie char *alloca ();
53840175f0Skstailey #    endif
543fb98d4aSespie #   endif
553fb98d4aSespie #  endif
563fb98d4aSespie # endif
57*a1acfa9bSespie #endif
583fb98d4aSespie 
593fb98d4aSespie #include <stdlib.h>
603fb98d4aSespie #include <string.h>
61840175f0Skstailey 
62840175f0Skstailey #if defined HAVE_UNISTD_H || defined _LIBC
63840175f0Skstailey # include <unistd.h>
64840175f0Skstailey #endif
65840175f0Skstailey 
663fb98d4aSespie #ifdef _LIBC
673fb98d4aSespie # include <langinfo.h>
683fb98d4aSespie # include <locale.h>
69840175f0Skstailey #endif
70840175f0Skstailey 
713fb98d4aSespie #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
723fb98d4aSespie     || (defined _LIBC && defined _POSIX_MAPPED_FILES)
733fb98d4aSespie # include <sys/mman.h>
743fb98d4aSespie # undef HAVE_MMAP
753fb98d4aSespie # define HAVE_MMAP	1
763fb98d4aSespie #else
773fb98d4aSespie # undef HAVE_MMAP
783fb98d4aSespie #endif
793fb98d4aSespie 
80*a1acfa9bSespie #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
81*a1acfa9bSespie # include <stdint.h>
82*a1acfa9bSespie #endif
83*a1acfa9bSespie #if defined HAVE_INTTYPES_H || defined _LIBC
84*a1acfa9bSespie # include <inttypes.h>
85*a1acfa9bSespie #endif
86*a1acfa9bSespie 
873fb98d4aSespie #include "gmo.h"
88840175f0Skstailey #include "gettextP.h"
89*a1acfa9bSespie #include "hash-string.h"
903fb98d4aSespie #include "plural-exp.h"
913fb98d4aSespie 
923fb98d4aSespie #ifdef _LIBC
933fb98d4aSespie # include "../locale/localeinfo.h"
943fb98d4aSespie #endif
95840175f0Skstailey 
96*a1acfa9bSespie /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
97*a1acfa9bSespie    Note that our fallback values need not be literal strings, because we don't
98*a1acfa9bSespie    use them with preprocessor string concatenation.  */
99*a1acfa9bSespie #if !defined PRId8 || PRI_MACROS_BROKEN
100*a1acfa9bSespie # undef PRId8
101*a1acfa9bSespie # define PRId8 "d"
102*a1acfa9bSespie #endif
103*a1acfa9bSespie #if !defined PRIi8 || PRI_MACROS_BROKEN
104*a1acfa9bSespie # undef PRIi8
105*a1acfa9bSespie # define PRIi8 "i"
106*a1acfa9bSespie #endif
107*a1acfa9bSespie #if !defined PRIo8 || PRI_MACROS_BROKEN
108*a1acfa9bSespie # undef PRIo8
109*a1acfa9bSespie # define PRIo8 "o"
110*a1acfa9bSespie #endif
111*a1acfa9bSespie #if !defined PRIu8 || PRI_MACROS_BROKEN
112*a1acfa9bSespie # undef PRIu8
113*a1acfa9bSespie # define PRIu8 "u"
114*a1acfa9bSespie #endif
115*a1acfa9bSespie #if !defined PRIx8 || PRI_MACROS_BROKEN
116*a1acfa9bSespie # undef PRIx8
117*a1acfa9bSespie # define PRIx8 "x"
118*a1acfa9bSespie #endif
119*a1acfa9bSespie #if !defined PRIX8 || PRI_MACROS_BROKEN
120*a1acfa9bSespie # undef PRIX8
121*a1acfa9bSespie # define PRIX8 "X"
122*a1acfa9bSespie #endif
123*a1acfa9bSespie #if !defined PRId16 || PRI_MACROS_BROKEN
124*a1acfa9bSespie # undef PRId16
125*a1acfa9bSespie # define PRId16 "d"
126*a1acfa9bSespie #endif
127*a1acfa9bSespie #if !defined PRIi16 || PRI_MACROS_BROKEN
128*a1acfa9bSespie # undef PRIi16
129*a1acfa9bSespie # define PRIi16 "i"
130*a1acfa9bSespie #endif
131*a1acfa9bSespie #if !defined PRIo16 || PRI_MACROS_BROKEN
132*a1acfa9bSespie # undef PRIo16
133*a1acfa9bSespie # define PRIo16 "o"
134*a1acfa9bSespie #endif
135*a1acfa9bSespie #if !defined PRIu16 || PRI_MACROS_BROKEN
136*a1acfa9bSespie # undef PRIu16
137*a1acfa9bSespie # define PRIu16 "u"
138*a1acfa9bSespie #endif
139*a1acfa9bSespie #if !defined PRIx16 || PRI_MACROS_BROKEN
140*a1acfa9bSespie # undef PRIx16
141*a1acfa9bSespie # define PRIx16 "x"
142*a1acfa9bSespie #endif
143*a1acfa9bSespie #if !defined PRIX16 || PRI_MACROS_BROKEN
144*a1acfa9bSespie # undef PRIX16
145*a1acfa9bSespie # define PRIX16 "X"
146*a1acfa9bSespie #endif
147*a1acfa9bSespie #if !defined PRId32 || PRI_MACROS_BROKEN
148*a1acfa9bSespie # undef PRId32
149*a1acfa9bSespie # define PRId32 "d"
150*a1acfa9bSespie #endif
151*a1acfa9bSespie #if !defined PRIi32 || PRI_MACROS_BROKEN
152*a1acfa9bSespie # undef PRIi32
153*a1acfa9bSespie # define PRIi32 "i"
154*a1acfa9bSespie #endif
155*a1acfa9bSespie #if !defined PRIo32 || PRI_MACROS_BROKEN
156*a1acfa9bSespie # undef PRIo32
157*a1acfa9bSespie # define PRIo32 "o"
158*a1acfa9bSespie #endif
159*a1acfa9bSespie #if !defined PRIu32 || PRI_MACROS_BROKEN
160*a1acfa9bSespie # undef PRIu32
161*a1acfa9bSespie # define PRIu32 "u"
162*a1acfa9bSespie #endif
163*a1acfa9bSespie #if !defined PRIx32 || PRI_MACROS_BROKEN
164*a1acfa9bSespie # undef PRIx32
165*a1acfa9bSespie # define PRIx32 "x"
166*a1acfa9bSespie #endif
167*a1acfa9bSespie #if !defined PRIX32 || PRI_MACROS_BROKEN
168*a1acfa9bSespie # undef PRIX32
169*a1acfa9bSespie # define PRIX32 "X"
170*a1acfa9bSespie #endif
171*a1acfa9bSespie #if !defined PRId64 || PRI_MACROS_BROKEN
172*a1acfa9bSespie # undef PRId64
173*a1acfa9bSespie # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
174*a1acfa9bSespie #endif
175*a1acfa9bSespie #if !defined PRIi64 || PRI_MACROS_BROKEN
176*a1acfa9bSespie # undef PRIi64
177*a1acfa9bSespie # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
178*a1acfa9bSespie #endif
179*a1acfa9bSespie #if !defined PRIo64 || PRI_MACROS_BROKEN
180*a1acfa9bSespie # undef PRIo64
181*a1acfa9bSespie # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
182*a1acfa9bSespie #endif
183*a1acfa9bSespie #if !defined PRIu64 || PRI_MACROS_BROKEN
184*a1acfa9bSespie # undef PRIu64
185*a1acfa9bSespie # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
186*a1acfa9bSespie #endif
187*a1acfa9bSespie #if !defined PRIx64 || PRI_MACROS_BROKEN
188*a1acfa9bSespie # undef PRIx64
189*a1acfa9bSespie # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
190*a1acfa9bSespie #endif
191*a1acfa9bSespie #if !defined PRIX64 || PRI_MACROS_BROKEN
192*a1acfa9bSespie # undef PRIX64
193*a1acfa9bSespie # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
194*a1acfa9bSespie #endif
195*a1acfa9bSespie #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
196*a1acfa9bSespie # undef PRIdLEAST8
197*a1acfa9bSespie # define PRIdLEAST8 "d"
198*a1acfa9bSespie #endif
199*a1acfa9bSespie #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
200*a1acfa9bSespie # undef PRIiLEAST8
201*a1acfa9bSespie # define PRIiLEAST8 "i"
202*a1acfa9bSespie #endif
203*a1acfa9bSespie #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
204*a1acfa9bSespie # undef PRIoLEAST8
205*a1acfa9bSespie # define PRIoLEAST8 "o"
206*a1acfa9bSespie #endif
207*a1acfa9bSespie #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
208*a1acfa9bSespie # undef PRIuLEAST8
209*a1acfa9bSespie # define PRIuLEAST8 "u"
210*a1acfa9bSespie #endif
211*a1acfa9bSespie #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
212*a1acfa9bSespie # undef PRIxLEAST8
213*a1acfa9bSespie # define PRIxLEAST8 "x"
214*a1acfa9bSespie #endif
215*a1acfa9bSespie #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
216*a1acfa9bSespie # undef PRIXLEAST8
217*a1acfa9bSespie # define PRIXLEAST8 "X"
218*a1acfa9bSespie #endif
219*a1acfa9bSespie #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
220*a1acfa9bSespie # undef PRIdLEAST16
221*a1acfa9bSespie # define PRIdLEAST16 "d"
222*a1acfa9bSespie #endif
223*a1acfa9bSespie #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
224*a1acfa9bSespie # undef PRIiLEAST16
225*a1acfa9bSespie # define PRIiLEAST16 "i"
226*a1acfa9bSespie #endif
227*a1acfa9bSespie #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
228*a1acfa9bSespie # undef PRIoLEAST16
229*a1acfa9bSespie # define PRIoLEAST16 "o"
230*a1acfa9bSespie #endif
231*a1acfa9bSespie #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
232*a1acfa9bSespie # undef PRIuLEAST16
233*a1acfa9bSespie # define PRIuLEAST16 "u"
234*a1acfa9bSespie #endif
235*a1acfa9bSespie #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
236*a1acfa9bSespie # undef PRIxLEAST16
237*a1acfa9bSespie # define PRIxLEAST16 "x"
238*a1acfa9bSespie #endif
239*a1acfa9bSespie #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
240*a1acfa9bSespie # undef PRIXLEAST16
241*a1acfa9bSespie # define PRIXLEAST16 "X"
242*a1acfa9bSespie #endif
243*a1acfa9bSespie #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
244*a1acfa9bSespie # undef PRIdLEAST32
245*a1acfa9bSespie # define PRIdLEAST32 "d"
246*a1acfa9bSespie #endif
247*a1acfa9bSespie #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
248*a1acfa9bSespie # undef PRIiLEAST32
249*a1acfa9bSespie # define PRIiLEAST32 "i"
250*a1acfa9bSespie #endif
251*a1acfa9bSespie #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
252*a1acfa9bSespie # undef PRIoLEAST32
253*a1acfa9bSespie # define PRIoLEAST32 "o"
254*a1acfa9bSespie #endif
255*a1acfa9bSespie #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
256*a1acfa9bSespie # undef PRIuLEAST32
257*a1acfa9bSespie # define PRIuLEAST32 "u"
258*a1acfa9bSespie #endif
259*a1acfa9bSespie #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
260*a1acfa9bSespie # undef PRIxLEAST32
261*a1acfa9bSespie # define PRIxLEAST32 "x"
262*a1acfa9bSespie #endif
263*a1acfa9bSespie #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
264*a1acfa9bSespie # undef PRIXLEAST32
265*a1acfa9bSespie # define PRIXLEAST32 "X"
266*a1acfa9bSespie #endif
267*a1acfa9bSespie #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
268*a1acfa9bSespie # undef PRIdLEAST64
269*a1acfa9bSespie # define PRIdLEAST64 PRId64
270*a1acfa9bSespie #endif
271*a1acfa9bSespie #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
272*a1acfa9bSespie # undef PRIiLEAST64
273*a1acfa9bSespie # define PRIiLEAST64 PRIi64
274*a1acfa9bSespie #endif
275*a1acfa9bSespie #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
276*a1acfa9bSespie # undef PRIoLEAST64
277*a1acfa9bSespie # define PRIoLEAST64 PRIo64
278*a1acfa9bSespie #endif
279*a1acfa9bSespie #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
280*a1acfa9bSespie # undef PRIuLEAST64
281*a1acfa9bSespie # define PRIuLEAST64 PRIu64
282*a1acfa9bSespie #endif
283*a1acfa9bSespie #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
284*a1acfa9bSespie # undef PRIxLEAST64
285*a1acfa9bSespie # define PRIxLEAST64 PRIx64
286*a1acfa9bSespie #endif
287*a1acfa9bSespie #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
288*a1acfa9bSespie # undef PRIXLEAST64
289*a1acfa9bSespie # define PRIXLEAST64 PRIX64
290*a1acfa9bSespie #endif
291*a1acfa9bSespie #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
292*a1acfa9bSespie # undef PRIdFAST8
293*a1acfa9bSespie # define PRIdFAST8 "d"
294*a1acfa9bSespie #endif
295*a1acfa9bSespie #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
296*a1acfa9bSespie # undef PRIiFAST8
297*a1acfa9bSespie # define PRIiFAST8 "i"
298*a1acfa9bSespie #endif
299*a1acfa9bSespie #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
300*a1acfa9bSespie # undef PRIoFAST8
301*a1acfa9bSespie # define PRIoFAST8 "o"
302*a1acfa9bSespie #endif
303*a1acfa9bSespie #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
304*a1acfa9bSespie # undef PRIuFAST8
305*a1acfa9bSespie # define PRIuFAST8 "u"
306*a1acfa9bSespie #endif
307*a1acfa9bSespie #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
308*a1acfa9bSespie # undef PRIxFAST8
309*a1acfa9bSespie # define PRIxFAST8 "x"
310*a1acfa9bSespie #endif
311*a1acfa9bSespie #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
312*a1acfa9bSespie # undef PRIXFAST8
313*a1acfa9bSespie # define PRIXFAST8 "X"
314*a1acfa9bSespie #endif
315*a1acfa9bSespie #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
316*a1acfa9bSespie # undef PRIdFAST16
317*a1acfa9bSespie # define PRIdFAST16 "d"
318*a1acfa9bSespie #endif
319*a1acfa9bSespie #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
320*a1acfa9bSespie # undef PRIiFAST16
321*a1acfa9bSespie # define PRIiFAST16 "i"
322*a1acfa9bSespie #endif
323*a1acfa9bSespie #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
324*a1acfa9bSespie # undef PRIoFAST16
325*a1acfa9bSespie # define PRIoFAST16 "o"
326*a1acfa9bSespie #endif
327*a1acfa9bSespie #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
328*a1acfa9bSespie # undef PRIuFAST16
329*a1acfa9bSespie # define PRIuFAST16 "u"
330*a1acfa9bSespie #endif
331*a1acfa9bSespie #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
332*a1acfa9bSespie # undef PRIxFAST16
333*a1acfa9bSespie # define PRIxFAST16 "x"
334*a1acfa9bSespie #endif
335*a1acfa9bSespie #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
336*a1acfa9bSespie # undef PRIXFAST16
337*a1acfa9bSespie # define PRIXFAST16 "X"
338*a1acfa9bSespie #endif
339*a1acfa9bSespie #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
340*a1acfa9bSespie # undef PRIdFAST32
341*a1acfa9bSespie # define PRIdFAST32 "d"
342*a1acfa9bSespie #endif
343*a1acfa9bSespie #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
344*a1acfa9bSespie # undef PRIiFAST32
345*a1acfa9bSespie # define PRIiFAST32 "i"
346*a1acfa9bSespie #endif
347*a1acfa9bSespie #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
348*a1acfa9bSespie # undef PRIoFAST32
349*a1acfa9bSespie # define PRIoFAST32 "o"
350*a1acfa9bSespie #endif
351*a1acfa9bSespie #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
352*a1acfa9bSespie # undef PRIuFAST32
353*a1acfa9bSespie # define PRIuFAST32 "u"
354*a1acfa9bSespie #endif
355*a1acfa9bSespie #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
356*a1acfa9bSespie # undef PRIxFAST32
357*a1acfa9bSespie # define PRIxFAST32 "x"
358*a1acfa9bSespie #endif
359*a1acfa9bSespie #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
360*a1acfa9bSespie # undef PRIXFAST32
361*a1acfa9bSespie # define PRIXFAST32 "X"
362*a1acfa9bSespie #endif
363*a1acfa9bSespie #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
364*a1acfa9bSespie # undef PRIdFAST64
365*a1acfa9bSespie # define PRIdFAST64 PRId64
366*a1acfa9bSespie #endif
367*a1acfa9bSespie #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
368*a1acfa9bSespie # undef PRIiFAST64
369*a1acfa9bSespie # define PRIiFAST64 PRIi64
370*a1acfa9bSespie #endif
371*a1acfa9bSespie #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
372*a1acfa9bSespie # undef PRIoFAST64
373*a1acfa9bSespie # define PRIoFAST64 PRIo64
374*a1acfa9bSespie #endif
375*a1acfa9bSespie #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
376*a1acfa9bSespie # undef PRIuFAST64
377*a1acfa9bSespie # define PRIuFAST64 PRIu64
378*a1acfa9bSespie #endif
379*a1acfa9bSespie #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
380*a1acfa9bSespie # undef PRIxFAST64
381*a1acfa9bSespie # define PRIxFAST64 PRIx64
382*a1acfa9bSespie #endif
383*a1acfa9bSespie #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
384*a1acfa9bSespie # undef PRIXFAST64
385*a1acfa9bSespie # define PRIXFAST64 PRIX64
386*a1acfa9bSespie #endif
387*a1acfa9bSespie #if !defined PRIdMAX || PRI_MACROS_BROKEN
388*a1acfa9bSespie # undef PRIdMAX
389*a1acfa9bSespie # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
390*a1acfa9bSespie #endif
391*a1acfa9bSespie #if !defined PRIiMAX || PRI_MACROS_BROKEN
392*a1acfa9bSespie # undef PRIiMAX
393*a1acfa9bSespie # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
394*a1acfa9bSespie #endif
395*a1acfa9bSespie #if !defined PRIoMAX || PRI_MACROS_BROKEN
396*a1acfa9bSespie # undef PRIoMAX
397*a1acfa9bSespie # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
398*a1acfa9bSespie #endif
399*a1acfa9bSespie #if !defined PRIuMAX || PRI_MACROS_BROKEN
400*a1acfa9bSespie # undef PRIuMAX
401*a1acfa9bSespie # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
402*a1acfa9bSespie #endif
403*a1acfa9bSespie #if !defined PRIxMAX || PRI_MACROS_BROKEN
404*a1acfa9bSespie # undef PRIxMAX
405*a1acfa9bSespie # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
406*a1acfa9bSespie #endif
407*a1acfa9bSespie #if !defined PRIXMAX || PRI_MACROS_BROKEN
408*a1acfa9bSespie # undef PRIXMAX
409*a1acfa9bSespie # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
410*a1acfa9bSespie #endif
411*a1acfa9bSespie #if !defined PRIdPTR || PRI_MACROS_BROKEN
412*a1acfa9bSespie # undef PRIdPTR
413*a1acfa9bSespie # define PRIdPTR \
414*a1acfa9bSespie   (sizeof (void *) == sizeof (long) ? "ld" : \
415*a1acfa9bSespie    sizeof (void *) == sizeof (int) ? "d" : \
416*a1acfa9bSespie    "lld")
417*a1acfa9bSespie #endif
418*a1acfa9bSespie #if !defined PRIiPTR || PRI_MACROS_BROKEN
419*a1acfa9bSespie # undef PRIiPTR
420*a1acfa9bSespie # define PRIiPTR \
421*a1acfa9bSespie   (sizeof (void *) == sizeof (long) ? "li" : \
422*a1acfa9bSespie    sizeof (void *) == sizeof (int) ? "i" : \
423*a1acfa9bSespie    "lli")
424*a1acfa9bSespie #endif
425*a1acfa9bSespie #if !defined PRIoPTR || PRI_MACROS_BROKEN
426*a1acfa9bSespie # undef PRIoPTR
427*a1acfa9bSespie # define PRIoPTR \
428*a1acfa9bSespie   (sizeof (void *) == sizeof (long) ? "lo" : \
429*a1acfa9bSespie    sizeof (void *) == sizeof (int) ? "o" : \
430*a1acfa9bSespie    "llo")
431*a1acfa9bSespie #endif
432*a1acfa9bSespie #if !defined PRIuPTR || PRI_MACROS_BROKEN
433*a1acfa9bSespie # undef PRIuPTR
434*a1acfa9bSespie # define PRIuPTR \
435*a1acfa9bSespie   (sizeof (void *) == sizeof (long) ? "lu" : \
436*a1acfa9bSespie    sizeof (void *) == sizeof (int) ? "u" : \
437*a1acfa9bSespie    "llu")
438*a1acfa9bSespie #endif
439*a1acfa9bSespie #if !defined PRIxPTR || PRI_MACROS_BROKEN
440*a1acfa9bSespie # undef PRIxPTR
441*a1acfa9bSespie # define PRIxPTR \
442*a1acfa9bSespie   (sizeof (void *) == sizeof (long) ? "lx" : \
443*a1acfa9bSespie    sizeof (void *) == sizeof (int) ? "x" : \
444*a1acfa9bSespie    "llx")
445*a1acfa9bSespie #endif
446*a1acfa9bSespie #if !defined PRIXPTR || PRI_MACROS_BROKEN
447*a1acfa9bSespie # undef PRIXPTR
448*a1acfa9bSespie # define PRIXPTR \
449*a1acfa9bSespie   (sizeof (void *) == sizeof (long) ? "lX" : \
450*a1acfa9bSespie    sizeof (void *) == sizeof (int) ? "X" : \
451*a1acfa9bSespie    "llX")
452*a1acfa9bSespie #endif
453*a1acfa9bSespie 
454840175f0Skstailey /* @@ end of prolog @@ */
455840175f0Skstailey 
456840175f0Skstailey #ifdef _LIBC
45728ea187bSespie /* Rename the non ISO C functions.  This is required by the standard
45828ea187bSespie    because some ISO C functions will require linking with this object
459840175f0Skstailey    file and the name space must not be polluted.  */
460840175f0Skstailey # define open   __open
461840175f0Skstailey # define close  __close
462840175f0Skstailey # define read   __read
463840175f0Skstailey # define mmap   __mmap
464840175f0Skstailey # define munmap __munmap
465840175f0Skstailey #endif
466840175f0Skstailey 
4673fb98d4aSespie /* For those losing systems which don't have `alloca' we have to add
4683fb98d4aSespie    some additional code emulating it.  */
4693fb98d4aSespie #ifdef HAVE_ALLOCA
4703fb98d4aSespie # define freea(p) /* nothing */
4713fb98d4aSespie #else
4723fb98d4aSespie # define alloca(n) malloc (n)
4733fb98d4aSespie # define freea(p) free (p)
4743fb98d4aSespie #endif
4753fb98d4aSespie 
4763fb98d4aSespie /* For systems that distinguish between text and binary I/O.
4773fb98d4aSespie    O_BINARY is usually declared in <fcntl.h>. */
4783fb98d4aSespie #if !defined O_BINARY && defined _O_BINARY
4793fb98d4aSespie   /* For MSC-compatible compilers.  */
4803fb98d4aSespie # define O_BINARY _O_BINARY
4813fb98d4aSespie # define O_TEXT _O_TEXT
4823fb98d4aSespie #endif
4833fb98d4aSespie #ifdef __BEOS__
4843fb98d4aSespie   /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect.  */
4853fb98d4aSespie # undef O_BINARY
4863fb98d4aSespie # undef O_TEXT
4873fb98d4aSespie #endif
4883fb98d4aSespie /* On reasonable systems, binary I/O is the default.  */
4893fb98d4aSespie #ifndef O_BINARY
4903fb98d4aSespie # define O_BINARY 0
4913fb98d4aSespie #endif
4923fb98d4aSespie 
493*a1acfa9bSespie 
494840175f0Skstailey /* We need a sign, whether a new catalog was loaded, which can be associated
495840175f0Skstailey    with all translations.  This is important if the translations are
496840175f0Skstailey    cached by one of GCC's features.  */
4973fb98d4aSespie int _nl_msg_cat_cntr;
498840175f0Skstailey 
499840175f0Skstailey 
500*a1acfa9bSespie /* Expand a system dependent string segment.  Return NULL if unsupported.  */
501*a1acfa9bSespie static const char *
get_sysdep_segment_value(const char * name)502*a1acfa9bSespie get_sysdep_segment_value (const char *name)
503*a1acfa9bSespie {
504*a1acfa9bSespie   /* Test for an ISO C 99 section 7.8.1 format string directive.
505*a1acfa9bSespie      Syntax:
506*a1acfa9bSespie      P R I { d | i | o | u | x | X }
507*a1acfa9bSespie      { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR }  */
508*a1acfa9bSespie   /* We don't use a table of 14 times 6 'const char *' strings here, because
509*a1acfa9bSespie      data relocations cost startup time.  */
510*a1acfa9bSespie   if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I')
511*a1acfa9bSespie     {
512*a1acfa9bSespie       if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u'
513*a1acfa9bSespie 	  || name[3] == 'x' || name[3] == 'X')
514*a1acfa9bSespie 	{
515*a1acfa9bSespie 	  if (name[4] == '8' && name[5] == '\0')
516*a1acfa9bSespie 	    {
517*a1acfa9bSespie 	      if (name[3] == 'd')
518*a1acfa9bSespie 		return PRId8;
519*a1acfa9bSespie 	      if (name[3] == 'i')
520*a1acfa9bSespie 		return PRIi8;
521*a1acfa9bSespie 	      if (name[3] == 'o')
522*a1acfa9bSespie 		return PRIo8;
523*a1acfa9bSespie 	      if (name[3] == 'u')
524*a1acfa9bSespie 		return PRIu8;
525*a1acfa9bSespie 	      if (name[3] == 'x')
526*a1acfa9bSespie 		return PRIx8;
527*a1acfa9bSespie 	      if (name[3] == 'X')
528*a1acfa9bSespie 		return PRIX8;
529*a1acfa9bSespie 	      abort ();
530*a1acfa9bSespie 	    }
531*a1acfa9bSespie 	  if (name[4] == '1' && name[5] == '6' && name[6] == '\0')
532*a1acfa9bSespie 	    {
533*a1acfa9bSespie 	      if (name[3] == 'd')
534*a1acfa9bSespie 		return PRId16;
535*a1acfa9bSespie 	      if (name[3] == 'i')
536*a1acfa9bSespie 		return PRIi16;
537*a1acfa9bSespie 	      if (name[3] == 'o')
538*a1acfa9bSespie 		return PRIo16;
539*a1acfa9bSespie 	      if (name[3] == 'u')
540*a1acfa9bSespie 		return PRIu16;
541*a1acfa9bSespie 	      if (name[3] == 'x')
542*a1acfa9bSespie 		return PRIx16;
543*a1acfa9bSespie 	      if (name[3] == 'X')
544*a1acfa9bSespie 		return PRIX16;
545*a1acfa9bSespie 	      abort ();
546*a1acfa9bSespie 	    }
547*a1acfa9bSespie 	  if (name[4] == '3' && name[5] == '2' && name[6] == '\0')
548*a1acfa9bSespie 	    {
549*a1acfa9bSespie 	      if (name[3] == 'd')
550*a1acfa9bSespie 		return PRId32;
551*a1acfa9bSespie 	      if (name[3] == 'i')
552*a1acfa9bSespie 		return PRIi32;
553*a1acfa9bSespie 	      if (name[3] == 'o')
554*a1acfa9bSespie 		return PRIo32;
555*a1acfa9bSespie 	      if (name[3] == 'u')
556*a1acfa9bSespie 		return PRIu32;
557*a1acfa9bSespie 	      if (name[3] == 'x')
558*a1acfa9bSespie 		return PRIx32;
559*a1acfa9bSespie 	      if (name[3] == 'X')
560*a1acfa9bSespie 		return PRIX32;
561*a1acfa9bSespie 	      abort ();
562*a1acfa9bSespie 	    }
563*a1acfa9bSespie 	  if (name[4] == '6' && name[5] == '4' && name[6] == '\0')
564*a1acfa9bSespie 	    {
565*a1acfa9bSespie 	      if (name[3] == 'd')
566*a1acfa9bSespie 		return PRId64;
567*a1acfa9bSespie 	      if (name[3] == 'i')
568*a1acfa9bSespie 		return PRIi64;
569*a1acfa9bSespie 	      if (name[3] == 'o')
570*a1acfa9bSespie 		return PRIo64;
571*a1acfa9bSespie 	      if (name[3] == 'u')
572*a1acfa9bSespie 		return PRIu64;
573*a1acfa9bSespie 	      if (name[3] == 'x')
574*a1acfa9bSespie 		return PRIx64;
575*a1acfa9bSespie 	      if (name[3] == 'X')
576*a1acfa9bSespie 		return PRIX64;
577*a1acfa9bSespie 	      abort ();
578*a1acfa9bSespie 	    }
579*a1acfa9bSespie 	  if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A'
580*a1acfa9bSespie 	      && name[7] == 'S' && name[8] == 'T')
581*a1acfa9bSespie 	    {
582*a1acfa9bSespie 	      if (name[9] == '8' && name[10] == '\0')
583*a1acfa9bSespie 		{
584*a1acfa9bSespie 		  if (name[3] == 'd')
585*a1acfa9bSespie 		    return PRIdLEAST8;
586*a1acfa9bSespie 		  if (name[3] == 'i')
587*a1acfa9bSespie 		    return PRIiLEAST8;
588*a1acfa9bSespie 		  if (name[3] == 'o')
589*a1acfa9bSespie 		    return PRIoLEAST8;
590*a1acfa9bSespie 		  if (name[3] == 'u')
591*a1acfa9bSespie 		    return PRIuLEAST8;
592*a1acfa9bSespie 		  if (name[3] == 'x')
593*a1acfa9bSespie 		    return PRIxLEAST8;
594*a1acfa9bSespie 		  if (name[3] == 'X')
595*a1acfa9bSespie 		    return PRIXLEAST8;
596*a1acfa9bSespie 		  abort ();
597*a1acfa9bSespie 		}
598*a1acfa9bSespie 	      if (name[9] == '1' && name[10] == '6' && name[11] == '\0')
599*a1acfa9bSespie 		{
600*a1acfa9bSespie 		  if (name[3] == 'd')
601*a1acfa9bSespie 		    return PRIdLEAST16;
602*a1acfa9bSespie 		  if (name[3] == 'i')
603*a1acfa9bSespie 		    return PRIiLEAST16;
604*a1acfa9bSespie 		  if (name[3] == 'o')
605*a1acfa9bSespie 		    return PRIoLEAST16;
606*a1acfa9bSespie 		  if (name[3] == 'u')
607*a1acfa9bSespie 		    return PRIuLEAST16;
608*a1acfa9bSespie 		  if (name[3] == 'x')
609*a1acfa9bSespie 		    return PRIxLEAST16;
610*a1acfa9bSespie 		  if (name[3] == 'X')
611*a1acfa9bSespie 		    return PRIXLEAST16;
612*a1acfa9bSespie 		  abort ();
613*a1acfa9bSespie 		}
614*a1acfa9bSespie 	      if (name[9] == '3' && name[10] == '2' && name[11] == '\0')
615*a1acfa9bSespie 		{
616*a1acfa9bSespie 		  if (name[3] == 'd')
617*a1acfa9bSespie 		    return PRIdLEAST32;
618*a1acfa9bSespie 		  if (name[3] == 'i')
619*a1acfa9bSespie 		    return PRIiLEAST32;
620*a1acfa9bSespie 		  if (name[3] == 'o')
621*a1acfa9bSespie 		    return PRIoLEAST32;
622*a1acfa9bSespie 		  if (name[3] == 'u')
623*a1acfa9bSespie 		    return PRIuLEAST32;
624*a1acfa9bSespie 		  if (name[3] == 'x')
625*a1acfa9bSespie 		    return PRIxLEAST32;
626*a1acfa9bSespie 		  if (name[3] == 'X')
627*a1acfa9bSespie 		    return PRIXLEAST32;
628*a1acfa9bSespie 		  abort ();
629*a1acfa9bSespie 		}
630*a1acfa9bSespie 	      if (name[9] == '6' && name[10] == '4' && name[11] == '\0')
631*a1acfa9bSespie 		{
632*a1acfa9bSespie 		  if (name[3] == 'd')
633*a1acfa9bSespie 		    return PRIdLEAST64;
634*a1acfa9bSespie 		  if (name[3] == 'i')
635*a1acfa9bSespie 		    return PRIiLEAST64;
636*a1acfa9bSespie 		  if (name[3] == 'o')
637*a1acfa9bSespie 		    return PRIoLEAST64;
638*a1acfa9bSespie 		  if (name[3] == 'u')
639*a1acfa9bSespie 		    return PRIuLEAST64;
640*a1acfa9bSespie 		  if (name[3] == 'x')
641*a1acfa9bSespie 		    return PRIxLEAST64;
642*a1acfa9bSespie 		  if (name[3] == 'X')
643*a1acfa9bSespie 		    return PRIXLEAST64;
644*a1acfa9bSespie 		  abort ();
645*a1acfa9bSespie 		}
646*a1acfa9bSespie 	    }
647*a1acfa9bSespie 	  if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S'
648*a1acfa9bSespie 	      && name[7] == 'T')
649*a1acfa9bSespie 	    {
650*a1acfa9bSespie 	      if (name[8] == '8' && name[9] == '\0')
651*a1acfa9bSespie 		{
652*a1acfa9bSespie 		  if (name[3] == 'd')
653*a1acfa9bSespie 		    return PRIdFAST8;
654*a1acfa9bSespie 		  if (name[3] == 'i')
655*a1acfa9bSespie 		    return PRIiFAST8;
656*a1acfa9bSespie 		  if (name[3] == 'o')
657*a1acfa9bSespie 		    return PRIoFAST8;
658*a1acfa9bSespie 		  if (name[3] == 'u')
659*a1acfa9bSespie 		    return PRIuFAST8;
660*a1acfa9bSespie 		  if (name[3] == 'x')
661*a1acfa9bSespie 		    return PRIxFAST8;
662*a1acfa9bSespie 		  if (name[3] == 'X')
663*a1acfa9bSespie 		    return PRIXFAST8;
664*a1acfa9bSespie 		  abort ();
665*a1acfa9bSespie 		}
666*a1acfa9bSespie 	      if (name[8] == '1' && name[9] == '6' && name[10] == '\0')
667*a1acfa9bSespie 		{
668*a1acfa9bSespie 		  if (name[3] == 'd')
669*a1acfa9bSespie 		    return PRIdFAST16;
670*a1acfa9bSespie 		  if (name[3] == 'i')
671*a1acfa9bSespie 		    return PRIiFAST16;
672*a1acfa9bSespie 		  if (name[3] == 'o')
673*a1acfa9bSespie 		    return PRIoFAST16;
674*a1acfa9bSespie 		  if (name[3] == 'u')
675*a1acfa9bSespie 		    return PRIuFAST16;
676*a1acfa9bSespie 		  if (name[3] == 'x')
677*a1acfa9bSespie 		    return PRIxFAST16;
678*a1acfa9bSespie 		  if (name[3] == 'X')
679*a1acfa9bSespie 		    return PRIXFAST16;
680*a1acfa9bSespie 		  abort ();
681*a1acfa9bSespie 		}
682*a1acfa9bSespie 	      if (name[8] == '3' && name[9] == '2' && name[10] == '\0')
683*a1acfa9bSespie 		{
684*a1acfa9bSespie 		  if (name[3] == 'd')
685*a1acfa9bSespie 		    return PRIdFAST32;
686*a1acfa9bSespie 		  if (name[3] == 'i')
687*a1acfa9bSespie 		    return PRIiFAST32;
688*a1acfa9bSespie 		  if (name[3] == 'o')
689*a1acfa9bSespie 		    return PRIoFAST32;
690*a1acfa9bSespie 		  if (name[3] == 'u')
691*a1acfa9bSespie 		    return PRIuFAST32;
692*a1acfa9bSespie 		  if (name[3] == 'x')
693*a1acfa9bSespie 		    return PRIxFAST32;
694*a1acfa9bSespie 		  if (name[3] == 'X')
695*a1acfa9bSespie 		    return PRIXFAST32;
696*a1acfa9bSespie 		  abort ();
697*a1acfa9bSespie 		}
698*a1acfa9bSespie 	      if (name[8] == '6' && name[9] == '4' && name[10] == '\0')
699*a1acfa9bSespie 		{
700*a1acfa9bSespie 		  if (name[3] == 'd')
701*a1acfa9bSespie 		    return PRIdFAST64;
702*a1acfa9bSespie 		  if (name[3] == 'i')
703*a1acfa9bSespie 		    return PRIiFAST64;
704*a1acfa9bSespie 		  if (name[3] == 'o')
705*a1acfa9bSespie 		    return PRIoFAST64;
706*a1acfa9bSespie 		  if (name[3] == 'u')
707*a1acfa9bSespie 		    return PRIuFAST64;
708*a1acfa9bSespie 		  if (name[3] == 'x')
709*a1acfa9bSespie 		    return PRIxFAST64;
710*a1acfa9bSespie 		  if (name[3] == 'X')
711*a1acfa9bSespie 		    return PRIXFAST64;
712*a1acfa9bSespie 		  abort ();
713*a1acfa9bSespie 		}
714*a1acfa9bSespie 	    }
715*a1acfa9bSespie 	  if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X'
716*a1acfa9bSespie 	      && name[7] == '\0')
717*a1acfa9bSespie 	    {
718*a1acfa9bSespie 	      if (name[3] == 'd')
719*a1acfa9bSespie 		return PRIdMAX;
720*a1acfa9bSespie 	      if (name[3] == 'i')
721*a1acfa9bSespie 		return PRIiMAX;
722*a1acfa9bSespie 	      if (name[3] == 'o')
723*a1acfa9bSespie 		return PRIoMAX;
724*a1acfa9bSespie 	      if (name[3] == 'u')
725*a1acfa9bSespie 		return PRIuMAX;
726*a1acfa9bSespie 	      if (name[3] == 'x')
727*a1acfa9bSespie 		return PRIxMAX;
728*a1acfa9bSespie 	      if (name[3] == 'X')
729*a1acfa9bSespie 		return PRIXMAX;
730*a1acfa9bSespie 	      abort ();
731*a1acfa9bSespie 	    }
732*a1acfa9bSespie 	  if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R'
733*a1acfa9bSespie 	      && name[7] == '\0')
734*a1acfa9bSespie 	    {
735*a1acfa9bSespie 	      if (name[3] == 'd')
736*a1acfa9bSespie 		return PRIdPTR;
737*a1acfa9bSespie 	      if (name[3] == 'i')
738*a1acfa9bSespie 		return PRIiPTR;
739*a1acfa9bSespie 	      if (name[3] == 'o')
740*a1acfa9bSespie 		return PRIoPTR;
741*a1acfa9bSespie 	      if (name[3] == 'u')
742*a1acfa9bSespie 		return PRIuPTR;
743*a1acfa9bSespie 	      if (name[3] == 'x')
744*a1acfa9bSespie 		return PRIxPTR;
745*a1acfa9bSespie 	      if (name[3] == 'X')
746*a1acfa9bSespie 		return PRIXPTR;
747*a1acfa9bSespie 	      abort ();
748*a1acfa9bSespie 	    }
749*a1acfa9bSespie 	}
750*a1acfa9bSespie     }
751*a1acfa9bSespie   /* Test for a glibc specific printf() format directive flag.  */
752*a1acfa9bSespie   if (name[0] == 'I' && name[1] == '\0')
753*a1acfa9bSespie     {
754*a1acfa9bSespie #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
755*a1acfa9bSespie       /* The 'I' flag, in numeric format directives, replaces ASCII digits
756*a1acfa9bSespie 	 with the 'outdigits' defined in the LC_CTYPE locale facet.  This is
757*a1acfa9bSespie 	 used for Farsi (Persian) and maybe Arabic.  */
758*a1acfa9bSespie       return "I";
759*a1acfa9bSespie #else
760*a1acfa9bSespie       return "";
761*a1acfa9bSespie #endif
762*a1acfa9bSespie     }
763*a1acfa9bSespie   /* Other system dependent strings are not valid.  */
764*a1acfa9bSespie   return NULL;
765*a1acfa9bSespie }
766*a1acfa9bSespie 
7673fb98d4aSespie /* Initialize the codeset dependent parts of an opened message catalog.
7683fb98d4aSespie    Return the header entry.  */
7693fb98d4aSespie const char *
7703fb98d4aSespie internal_function
_nl_init_domain_conv(struct loaded_l10nfile * domain_file,struct loaded_domain * domain,struct binding * domainbinding)771*a1acfa9bSespie _nl_init_domain_conv (struct loaded_l10nfile *domain_file,
772*a1acfa9bSespie 		      struct loaded_domain *domain,
773*a1acfa9bSespie 		      struct binding *domainbinding)
7743fb98d4aSespie {
7753fb98d4aSespie   /* Find out about the character set the file is encoded with.
7763fb98d4aSespie      This can be found (in textual form) in the entry "".  If this
7773fb98d4aSespie      entry does not exist or if this does not contain the `charset='
7783fb98d4aSespie      information, we will assume the charset matches the one the
7793fb98d4aSespie      current locale and we don't have to perform any conversion.  */
7803fb98d4aSespie   char *nullentry;
7813fb98d4aSespie   size_t nullentrylen;
7823fb98d4aSespie 
7833fb98d4aSespie   /* Preinitialize fields, to avoid recursion during _nl_find_msg.  */
7843fb98d4aSespie   domain->codeset_cntr =
7853fb98d4aSespie     (domainbinding != NULL ? domainbinding->codeset_cntr : 0);
7863fb98d4aSespie #ifdef _LIBC
7873fb98d4aSespie   domain->conv = (__gconv_t) -1;
7883fb98d4aSespie #else
7893fb98d4aSespie # if HAVE_ICONV
7903fb98d4aSespie   domain->conv = (iconv_t) -1;
7913fb98d4aSespie # endif
7923fb98d4aSespie #endif
7933fb98d4aSespie   domain->conv_tab = NULL;
7943fb98d4aSespie 
7953fb98d4aSespie   /* Get the header entry.  */
7963fb98d4aSespie   nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen);
7973fb98d4aSespie 
7983fb98d4aSespie   if (nullentry != NULL)
7993fb98d4aSespie     {
8003fb98d4aSespie #if defined _LIBC || HAVE_ICONV
8013fb98d4aSespie       const char *charsetstr;
8023fb98d4aSespie 
8033fb98d4aSespie       charsetstr = strstr (nullentry, "charset=");
8043fb98d4aSespie       if (charsetstr != NULL)
8053fb98d4aSespie 	{
8063fb98d4aSespie 	  size_t len;
8073fb98d4aSespie 	  char *charset;
8083fb98d4aSespie 	  const char *outcharset;
8093fb98d4aSespie 
8103fb98d4aSespie 	  charsetstr += strlen ("charset=");
8113fb98d4aSespie 	  len = strcspn (charsetstr, " \t\n");
8123fb98d4aSespie 
8133fb98d4aSespie 	  charset = (char *) alloca (len + 1);
8143fb98d4aSespie # if defined _LIBC || HAVE_MEMPCPY
8153fb98d4aSespie 	  *((char *) mempcpy (charset, charsetstr, len)) = '\0';
8163fb98d4aSespie # else
8173fb98d4aSespie 	  memcpy (charset, charsetstr, len);
8183fb98d4aSespie 	  charset[len] = '\0';
8193fb98d4aSespie # endif
8203fb98d4aSespie 
8213fb98d4aSespie 	  /* The output charset should normally be determined by the
8223fb98d4aSespie 	     locale.  But sometimes the locale is not used or not correctly
8233fb98d4aSespie 	     set up, so we provide a possibility for the user to override
8243fb98d4aSespie 	     this.  Moreover, the value specified through
8253fb98d4aSespie 	     bind_textdomain_codeset overrides both.  */
8263fb98d4aSespie 	  if (domainbinding != NULL && domainbinding->codeset != NULL)
8273fb98d4aSespie 	    outcharset = domainbinding->codeset;
8283fb98d4aSespie 	  else
8293fb98d4aSespie 	    {
8303fb98d4aSespie 	      outcharset = getenv ("OUTPUT_CHARSET");
8313fb98d4aSespie 	      if (outcharset == NULL || outcharset[0] == '\0')
8323fb98d4aSespie 		{
8333fb98d4aSespie # ifdef _LIBC
834*a1acfa9bSespie 		  outcharset = _NL_CURRENT (LC_CTYPE, CODESET);
8353fb98d4aSespie # else
8363fb98d4aSespie #  if HAVE_ICONV
837*a1acfa9bSespie 		  extern const char *locale_charset (void);
8383fb98d4aSespie 		  outcharset = locale_charset ();
8393fb98d4aSespie #  endif
8403fb98d4aSespie # endif
8413fb98d4aSespie 		}
8423fb98d4aSespie 	    }
8433fb98d4aSespie 
8443fb98d4aSespie # ifdef _LIBC
8453fb98d4aSespie 	  /* We always want to use transliteration.  */
8463fb98d4aSespie 	  outcharset = norm_add_slashes (outcharset, "TRANSLIT");
8473fb98d4aSespie 	  charset = norm_add_slashes (charset, NULL);
8483fb98d4aSespie 	  if (__gconv_open (outcharset, charset, &domain->conv,
8493fb98d4aSespie 			    GCONV_AVOID_NOCONV)
8503fb98d4aSespie 	      != __GCONV_OK)
8513fb98d4aSespie 	    domain->conv = (__gconv_t) -1;
8523fb98d4aSespie # else
8533fb98d4aSespie #  if HAVE_ICONV
8543fb98d4aSespie 	  /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
8553fb98d4aSespie 	     we want to use transliteration.  */
8563fb98d4aSespie #   if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
8573fb98d4aSespie        || _LIBICONV_VERSION >= 0x0105
858*a1acfa9bSespie 	  if (strchr (outcharset, '/') == NULL)
8593fb98d4aSespie 	    {
860*a1acfa9bSespie 	      char *tmp;
861*a1acfa9bSespie 
862*a1acfa9bSespie 	      len = strlen (outcharset);
863*a1acfa9bSespie 	      tmp = (char *) alloca (len + 10 + 1);
8643fb98d4aSespie 	      memcpy (tmp, outcharset, len);
8653fb98d4aSespie 	      memcpy (tmp + len, "//TRANSLIT", 10 + 1);
8663fb98d4aSespie 	      outcharset = tmp;
867*a1acfa9bSespie 
868*a1acfa9bSespie 	      domain->conv = iconv_open (outcharset, charset);
869*a1acfa9bSespie 
870*a1acfa9bSespie 	      freea (outcharset);
8713fb98d4aSespie 	    }
872*a1acfa9bSespie 	  else
8733fb98d4aSespie #   endif
8743fb98d4aSespie 	    domain->conv = iconv_open (outcharset, charset);
8753fb98d4aSespie #  endif
8763fb98d4aSespie # endif
8773fb98d4aSespie 
8783fb98d4aSespie 	  freea (charset);
8793fb98d4aSespie 	}
8803fb98d4aSespie #endif /* _LIBC || HAVE_ICONV */
8813fb98d4aSespie     }
8823fb98d4aSespie 
8833fb98d4aSespie   return nullentry;
8843fb98d4aSespie }
8853fb98d4aSespie 
8863fb98d4aSespie /* Frees the codeset dependent parts of an opened message catalog.  */
8873fb98d4aSespie void
8883fb98d4aSespie internal_function
_nl_free_domain_conv(struct loaded_domain * domain)889*a1acfa9bSespie _nl_free_domain_conv (struct loaded_domain *domain)
8903fb98d4aSespie {
8913fb98d4aSespie   if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1)
8923fb98d4aSespie     free (domain->conv_tab);
8933fb98d4aSespie 
8943fb98d4aSespie #ifdef _LIBC
8953fb98d4aSespie   if (domain->conv != (__gconv_t) -1)
8963fb98d4aSespie     __gconv_close (domain->conv);
8973fb98d4aSespie #else
8983fb98d4aSespie # if HAVE_ICONV
8993fb98d4aSespie   if (domain->conv != (iconv_t) -1)
9003fb98d4aSespie     iconv_close (domain->conv);
9013fb98d4aSespie # endif
9023fb98d4aSespie #endif
9033fb98d4aSespie }
9043fb98d4aSespie 
905840175f0Skstailey /* Load the message catalogs specified by FILENAME.  If it is no valid
906840175f0Skstailey    message catalog do nothing.  */
907840175f0Skstailey void
9081cc83814Sespie internal_function
_nl_load_domain(struct loaded_l10nfile * domain_file,struct binding * domainbinding)909*a1acfa9bSespie _nl_load_domain (struct loaded_l10nfile *domain_file,
910*a1acfa9bSespie 		 struct binding *domainbinding)
911840175f0Skstailey {
912840175f0Skstailey   int fd;
9131cc83814Sespie   size_t size;
9143fb98d4aSespie #ifdef _LIBC
9153fb98d4aSespie   struct stat64 st;
9163fb98d4aSespie #else
917840175f0Skstailey   struct stat st;
918840175f0Skstailey #endif
9193fb98d4aSespie   struct mo_file_header *data = (struct mo_file_header *) -1;
9203fb98d4aSespie   int use_mmap = 0;
921840175f0Skstailey   struct loaded_domain *domain;
922*a1acfa9bSespie   int revision;
9233fb98d4aSespie   const char *nullentry;
924840175f0Skstailey 
925840175f0Skstailey   domain_file->decided = 1;
926840175f0Skstailey   domain_file->data = NULL;
927840175f0Skstailey 
9283fb98d4aSespie   /* Note that it would be useless to store domainbinding in domain_file
9293fb98d4aSespie      because domainbinding might be == NULL now but != NULL later (after
9303fb98d4aSespie      a call to bind_textdomain_codeset).  */
9313fb98d4aSespie 
932840175f0Skstailey   /* If the record does not represent a valid locale the FILENAME
933840175f0Skstailey      might be NULL.  This can happen when according to the given
934840175f0Skstailey      specification the locale file name is different for XPG and CEN
935840175f0Skstailey      syntax.  */
936840175f0Skstailey   if (domain_file->filename == NULL)
937840175f0Skstailey     return;
938840175f0Skstailey 
939840175f0Skstailey   /* Try to open the addressed file.  */
9403fb98d4aSespie   fd = open (domain_file->filename, O_RDONLY | O_BINARY);
941840175f0Skstailey   if (fd == -1)
942840175f0Skstailey     return;
943840175f0Skstailey 
944840175f0Skstailey   /* We must know about the size of the file.  */
9453fb98d4aSespie   if (
9463fb98d4aSespie #ifdef _LIBC
9473fb98d4aSespie       __builtin_expect (fstat64 (fd, &st) != 0, 0)
9483fb98d4aSespie #else
9493fb98d4aSespie       __builtin_expect (fstat (fd, &st) != 0, 0)
9503fb98d4aSespie #endif
9513fb98d4aSespie       || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
9523fb98d4aSespie       || __builtin_expect (size < sizeof (struct mo_file_header), 0))
953840175f0Skstailey     {
954840175f0Skstailey       /* Something went wrong.  */
955840175f0Skstailey       close (fd);
956840175f0Skstailey       return;
957840175f0Skstailey     }
958840175f0Skstailey 
9593fb98d4aSespie #ifdef HAVE_MMAP
960840175f0Skstailey   /* Now we are ready to load the file.  If mmap() is available we try
961840175f0Skstailey      this first.  If not available or it failed we try to load it.  */
9621cc83814Sespie   data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
963840175f0Skstailey 					 MAP_PRIVATE, fd, 0);
964840175f0Skstailey 
9653fb98d4aSespie   if (__builtin_expect (data != (struct mo_file_header *) -1, 1))
966840175f0Skstailey     {
967840175f0Skstailey       /* mmap() call was successful.  */
968840175f0Skstailey       close (fd);
969840175f0Skstailey       use_mmap = 1;
970840175f0Skstailey     }
971840175f0Skstailey #endif
972840175f0Skstailey 
973840175f0Skstailey   /* If the data is not yet available (i.e. mmap'ed) we try to load
974840175f0Skstailey      it manually.  */
975840175f0Skstailey   if (data == (struct mo_file_header *) -1)
976840175f0Skstailey     {
9771cc83814Sespie       size_t to_read;
978840175f0Skstailey       char *read_ptr;
979840175f0Skstailey 
9801cc83814Sespie       data = (struct mo_file_header *) malloc (size);
981840175f0Skstailey       if (data == NULL)
982840175f0Skstailey 	return;
983840175f0Skstailey 
9841cc83814Sespie       to_read = size;
985840175f0Skstailey       read_ptr = (char *) data;
986840175f0Skstailey       do
987840175f0Skstailey 	{
988840175f0Skstailey 	  long int nb = (long int) read (fd, read_ptr, to_read);
9893fb98d4aSespie 	  if (nb <= 0)
990840175f0Skstailey 	    {
9913fb98d4aSespie #ifdef EINTR
9923fb98d4aSespie 	      if (nb == -1 && errno == EINTR)
9933fb98d4aSespie 		continue;
9943fb98d4aSespie #endif
995840175f0Skstailey 	      close (fd);
996840175f0Skstailey 	      return;
997840175f0Skstailey 	    }
998840175f0Skstailey 	  read_ptr += nb;
999840175f0Skstailey 	  to_read -= nb;
1000840175f0Skstailey 	}
1001840175f0Skstailey       while (to_read > 0);
1002840175f0Skstailey 
1003840175f0Skstailey       close (fd);
1004840175f0Skstailey     }
1005840175f0Skstailey 
1006840175f0Skstailey   /* Using the magic number we can test whether it really is a message
1007840175f0Skstailey      catalog file.  */
10083fb98d4aSespie   if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED,
10093fb98d4aSespie 			0))
1010840175f0Skstailey     {
1011840175f0Skstailey       /* The magic number is wrong: not a message catalog file.  */
10123fb98d4aSespie #ifdef HAVE_MMAP
1013840175f0Skstailey       if (use_mmap)
10141cc83814Sespie 	munmap ((caddr_t) data, size);
1015840175f0Skstailey       else
1016840175f0Skstailey #endif
1017840175f0Skstailey 	free (data);
1018840175f0Skstailey       return;
1019840175f0Skstailey     }
1020840175f0Skstailey 
10213fb98d4aSespie   domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
10223fb98d4aSespie   if (domain == NULL)
1023840175f0Skstailey     return;
10243fb98d4aSespie   domain_file->data = domain;
1025840175f0Skstailey 
1026840175f0Skstailey   domain->data = (char *) data;
10271cc83814Sespie   domain->use_mmap = use_mmap;
10281cc83814Sespie   domain->mmap_size = size;
1029840175f0Skstailey   domain->must_swap = data->magic != _MAGIC;
1030*a1acfa9bSespie   domain->malloced = NULL;
1031840175f0Skstailey 
1032840175f0Skstailey   /* Fill in the information about the available tables.  */
1033*a1acfa9bSespie   revision = W (domain->must_swap, data->revision);
1034*a1acfa9bSespie   /* We support only the major revisions 0 and 1.  */
1035*a1acfa9bSespie   switch (revision >> 16)
1036840175f0Skstailey     {
1037840175f0Skstailey     case 0:
1038*a1acfa9bSespie     case 1:
1039840175f0Skstailey       domain->nstrings = W (domain->must_swap, data->nstrings);
1040*a1acfa9bSespie       domain->orig_tab = (const struct string_desc *)
1041840175f0Skstailey 	((char *) data + W (domain->must_swap, data->orig_tab_offset));
1042*a1acfa9bSespie       domain->trans_tab = (const struct string_desc *)
1043840175f0Skstailey 	((char *) data + W (domain->must_swap, data->trans_tab_offset));
1044840175f0Skstailey       domain->hash_size = W (domain->must_swap, data->hash_tab_size);
1045*a1acfa9bSespie       domain->hash_tab =
1046*a1acfa9bSespie 	(domain->hash_size > 2
1047*a1acfa9bSespie 	 ? (const nls_uint32 *)
1048*a1acfa9bSespie 	   ((char *) data + W (domain->must_swap, data->hash_tab_offset))
1049*a1acfa9bSespie 	 : NULL);
1050*a1acfa9bSespie       domain->must_swap_hash_tab = domain->must_swap;
1051*a1acfa9bSespie 
1052*a1acfa9bSespie       /* Now dispatch on the minor revision.  */
1053*a1acfa9bSespie       switch (revision & 0xffff)
1054*a1acfa9bSespie 	{
1055*a1acfa9bSespie 	case 0:
1056*a1acfa9bSespie 	  domain->n_sysdep_strings = 0;
1057*a1acfa9bSespie 	  domain->orig_sysdep_tab = NULL;
1058*a1acfa9bSespie 	  domain->trans_sysdep_tab = NULL;
1059*a1acfa9bSespie 	  break;
1060*a1acfa9bSespie 	case 1:
1061*a1acfa9bSespie 	default:
1062*a1acfa9bSespie 	  {
1063*a1acfa9bSespie 	    nls_uint32 n_sysdep_strings;
1064*a1acfa9bSespie 
1065*a1acfa9bSespie 	    if (domain->hash_tab == NULL)
1066*a1acfa9bSespie 	      /* This is invalid.  These minor revisions need a hash table.  */
1067*a1acfa9bSespie 	      goto invalid;
1068*a1acfa9bSespie 
1069*a1acfa9bSespie 	    n_sysdep_strings =
1070*a1acfa9bSespie 	      W (domain->must_swap, data->n_sysdep_strings);
1071*a1acfa9bSespie 	    if (n_sysdep_strings > 0)
1072*a1acfa9bSespie 	      {
1073*a1acfa9bSespie 		nls_uint32 n_sysdep_segments;
1074*a1acfa9bSespie 		const struct sysdep_segment *sysdep_segments;
1075*a1acfa9bSespie 		const char **sysdep_segment_values;
1076*a1acfa9bSespie 		const nls_uint32 *orig_sysdep_tab;
1077*a1acfa9bSespie 		const nls_uint32 *trans_sysdep_tab;
1078*a1acfa9bSespie 		nls_uint32 n_inmem_sysdep_strings;
1079*a1acfa9bSespie 		size_t memneed;
1080*a1acfa9bSespie 		char *mem;
1081*a1acfa9bSespie 		struct sysdep_string_desc *inmem_orig_sysdep_tab;
1082*a1acfa9bSespie 		struct sysdep_string_desc *inmem_trans_sysdep_tab;
1083*a1acfa9bSespie 		nls_uint32 *inmem_hash_tab;
1084*a1acfa9bSespie 		unsigned int i, j;
1085*a1acfa9bSespie 
1086*a1acfa9bSespie 		/* Get the values of the system dependent segments.  */
1087*a1acfa9bSespie 		n_sysdep_segments =
1088*a1acfa9bSespie 		  W (domain->must_swap, data->n_sysdep_segments);
1089*a1acfa9bSespie 		sysdep_segments = (const struct sysdep_segment *)
1090*a1acfa9bSespie 		  ((char *) data
1091*a1acfa9bSespie 		   + W (domain->must_swap, data->sysdep_segments_offset));
1092*a1acfa9bSespie 		sysdep_segment_values =
1093*a1acfa9bSespie 		  alloca (n_sysdep_segments * sizeof (const char *));
1094*a1acfa9bSespie 		for (i = 0; i < n_sysdep_segments; i++)
1095*a1acfa9bSespie 		  {
1096*a1acfa9bSespie 		    const char *name =
1097*a1acfa9bSespie 		      (char *) data
1098*a1acfa9bSespie 		      + W (domain->must_swap, sysdep_segments[i].offset);
1099*a1acfa9bSespie 		    nls_uint32 namelen =
1100*a1acfa9bSespie 		      W (domain->must_swap, sysdep_segments[i].length);
1101*a1acfa9bSespie 
1102*a1acfa9bSespie 		    if (!(namelen > 0 && name[namelen - 1] == '\0'))
1103*a1acfa9bSespie 		      {
1104*a1acfa9bSespie 			freea (sysdep_segment_values);
1105*a1acfa9bSespie 			goto invalid;
1106*a1acfa9bSespie 		      }
1107*a1acfa9bSespie 
1108*a1acfa9bSespie 		    sysdep_segment_values[i] = get_sysdep_segment_value (name);
1109*a1acfa9bSespie 		  }
1110*a1acfa9bSespie 
1111*a1acfa9bSespie 		orig_sysdep_tab = (const nls_uint32 *)
1112*a1acfa9bSespie 		  ((char *) data
1113*a1acfa9bSespie 		   + W (domain->must_swap, data->orig_sysdep_tab_offset));
1114*a1acfa9bSespie 		trans_sysdep_tab = (const nls_uint32 *)
1115*a1acfa9bSespie 		  ((char *) data
1116*a1acfa9bSespie 		   + W (domain->must_swap, data->trans_sysdep_tab_offset));
1117*a1acfa9bSespie 
1118*a1acfa9bSespie 		/* Compute the amount of additional memory needed for the
1119*a1acfa9bSespie 		   system dependent strings and the augmented hash table.
1120*a1acfa9bSespie 		   At the same time, also drop string pairs which refer to
1121*a1acfa9bSespie 		   an undefined system dependent segment.  */
1122*a1acfa9bSespie 		n_inmem_sysdep_strings = 0;
1123*a1acfa9bSespie 		memneed = domain->hash_size * sizeof (nls_uint32);
1124*a1acfa9bSespie 		for (i = 0; i < n_sysdep_strings; i++)
1125*a1acfa9bSespie 		  {
1126*a1acfa9bSespie 		    int valid = 1;
1127*a1acfa9bSespie 		    size_t needs[2];
1128*a1acfa9bSespie 
1129*a1acfa9bSespie 		    for (j = 0; j < 2; j++)
1130*a1acfa9bSespie 		      {
1131*a1acfa9bSespie 			const struct sysdep_string *sysdep_string =
1132*a1acfa9bSespie 			  (const struct sysdep_string *)
1133*a1acfa9bSespie 			  ((char *) data
1134*a1acfa9bSespie 			   + W (domain->must_swap,
1135*a1acfa9bSespie 				j == 0
1136*a1acfa9bSespie 				? orig_sysdep_tab[i]
1137*a1acfa9bSespie 				: trans_sysdep_tab[i]));
1138*a1acfa9bSespie 			size_t need = 0;
1139*a1acfa9bSespie 			const struct segment_pair *p = sysdep_string->segments;
1140*a1acfa9bSespie 
1141*a1acfa9bSespie 			if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END)
1142*a1acfa9bSespie 			  for (p = sysdep_string->segments;; p++)
1143*a1acfa9bSespie 			    {
1144*a1acfa9bSespie 			      nls_uint32 sysdepref;
1145*a1acfa9bSespie 
1146*a1acfa9bSespie 			      need += W (domain->must_swap, p->segsize);
1147*a1acfa9bSespie 
1148*a1acfa9bSespie 			      sysdepref = W (domain->must_swap, p->sysdepref);
1149*a1acfa9bSespie 			      if (sysdepref == SEGMENTS_END)
1150*a1acfa9bSespie 				break;
1151*a1acfa9bSespie 
1152*a1acfa9bSespie 			      if (sysdepref >= n_sysdep_segments)
1153*a1acfa9bSespie 				{
1154*a1acfa9bSespie 				  /* Invalid.  */
1155*a1acfa9bSespie 				  freea (sysdep_segment_values);
1156*a1acfa9bSespie 				  goto invalid;
1157*a1acfa9bSespie 				}
1158*a1acfa9bSespie 
1159*a1acfa9bSespie 			      if (sysdep_segment_values[sysdepref] == NULL)
1160*a1acfa9bSespie 				{
1161*a1acfa9bSespie 				  /* This particular string pair is invalid.  */
1162*a1acfa9bSespie 				  valid = 0;
1163*a1acfa9bSespie 				  break;
1164*a1acfa9bSespie 				}
1165*a1acfa9bSespie 
1166*a1acfa9bSespie 			      need += strlen (sysdep_segment_values[sysdepref]);
1167*a1acfa9bSespie 			    }
1168*a1acfa9bSespie 
1169*a1acfa9bSespie 			needs[j] = need;
1170*a1acfa9bSespie 			if (!valid)
1171*a1acfa9bSespie 			  break;
1172*a1acfa9bSespie 		      }
1173*a1acfa9bSespie 
1174*a1acfa9bSespie 		    if (valid)
1175*a1acfa9bSespie 		      {
1176*a1acfa9bSespie 			n_inmem_sysdep_strings++;
1177*a1acfa9bSespie 			memneed += needs[0] + needs[1];
1178*a1acfa9bSespie 		      }
1179*a1acfa9bSespie 		  }
1180*a1acfa9bSespie 		memneed += 2 * n_inmem_sysdep_strings
1181*a1acfa9bSespie 			   * sizeof (struct sysdep_string_desc);
1182*a1acfa9bSespie 
1183*a1acfa9bSespie 		if (n_inmem_sysdep_strings > 0)
1184*a1acfa9bSespie 		  {
1185*a1acfa9bSespie 		    unsigned int k;
1186*a1acfa9bSespie 
1187*a1acfa9bSespie 		    /* Allocate additional memory.  */
1188*a1acfa9bSespie 		    mem = (char *) malloc (memneed);
1189*a1acfa9bSespie 		    if (mem == NULL)
1190*a1acfa9bSespie 		      goto invalid;
1191*a1acfa9bSespie 
1192*a1acfa9bSespie 		    domain->malloced = mem;
1193*a1acfa9bSespie 		    inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem;
1194*a1acfa9bSespie 		    mem += n_inmem_sysdep_strings
1195*a1acfa9bSespie 			   * sizeof (struct sysdep_string_desc);
1196*a1acfa9bSespie 		    inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem;
1197*a1acfa9bSespie 		    mem += n_inmem_sysdep_strings
1198*a1acfa9bSespie 			   * sizeof (struct sysdep_string_desc);
1199*a1acfa9bSespie 		    inmem_hash_tab = (nls_uint32 *) mem;
1200*a1acfa9bSespie 		    mem += domain->hash_size * sizeof (nls_uint32);
1201*a1acfa9bSespie 
1202*a1acfa9bSespie 		    /* Compute the system dependent strings.  */
1203*a1acfa9bSespie 		    k = 0;
1204*a1acfa9bSespie 		    for (i = 0; i < n_sysdep_strings; i++)
1205*a1acfa9bSespie 		      {
1206*a1acfa9bSespie 			int valid = 1;
1207*a1acfa9bSespie 
1208*a1acfa9bSespie 			for (j = 0; j < 2; j++)
1209*a1acfa9bSespie 			  {
1210*a1acfa9bSespie 			    const struct sysdep_string *sysdep_string =
1211*a1acfa9bSespie 			      (const struct sysdep_string *)
1212*a1acfa9bSespie 			      ((char *) data
1213*a1acfa9bSespie 			       + W (domain->must_swap,
1214*a1acfa9bSespie 				    j == 0
1215*a1acfa9bSespie 				    ? orig_sysdep_tab[i]
1216*a1acfa9bSespie 				    : trans_sysdep_tab[i]));
1217*a1acfa9bSespie 			    const struct segment_pair *p =
1218*a1acfa9bSespie 			      sysdep_string->segments;
1219*a1acfa9bSespie 
1220*a1acfa9bSespie 			    if (W (domain->must_swap, p->sysdepref)
1221*a1acfa9bSespie 				!= SEGMENTS_END)
1222*a1acfa9bSespie 			      for (p = sysdep_string->segments;; p++)
1223*a1acfa9bSespie 				{
1224*a1acfa9bSespie 				  nls_uint32 sysdepref;
1225*a1acfa9bSespie 
1226*a1acfa9bSespie 				  sysdepref =
1227*a1acfa9bSespie 				    W (domain->must_swap, p->sysdepref);
1228*a1acfa9bSespie 				  if (sysdepref == SEGMENTS_END)
1229*a1acfa9bSespie 				    break;
1230*a1acfa9bSespie 
1231*a1acfa9bSespie 				  if (sysdep_segment_values[sysdepref] == NULL)
1232*a1acfa9bSespie 				    {
1233*a1acfa9bSespie 				      /* This particular string pair is
1234*a1acfa9bSespie 					 invalid.  */
1235*a1acfa9bSespie 				      valid = 0;
1236*a1acfa9bSespie 				      break;
1237*a1acfa9bSespie 				    }
1238*a1acfa9bSespie 				}
1239*a1acfa9bSespie 
1240*a1acfa9bSespie 			    if (!valid)
1241*a1acfa9bSespie 			      break;
1242*a1acfa9bSespie 			  }
1243*a1acfa9bSespie 
1244*a1acfa9bSespie 			if (valid)
1245*a1acfa9bSespie 			  {
1246*a1acfa9bSespie 			    for (j = 0; j < 2; j++)
1247*a1acfa9bSespie 			      {
1248*a1acfa9bSespie 				const struct sysdep_string *sysdep_string =
1249*a1acfa9bSespie 				  (const struct sysdep_string *)
1250*a1acfa9bSespie 				  ((char *) data
1251*a1acfa9bSespie 				   + W (domain->must_swap,
1252*a1acfa9bSespie 					j == 0
1253*a1acfa9bSespie 					? orig_sysdep_tab[i]
1254*a1acfa9bSespie 					: trans_sysdep_tab[i]));
1255*a1acfa9bSespie 				const char *static_segments =
1256*a1acfa9bSespie 				  (char *) data
1257*a1acfa9bSespie 				  + W (domain->must_swap, sysdep_string->offset);
1258*a1acfa9bSespie 				const struct segment_pair *p =
1259*a1acfa9bSespie 				  sysdep_string->segments;
1260*a1acfa9bSespie 
1261*a1acfa9bSespie 				/* Concatenate the segments, and fill
1262*a1acfa9bSespie 				   inmem_orig_sysdep_tab[k] (for j == 0) and
1263*a1acfa9bSespie 				   inmem_trans_sysdep_tab[k] (for j == 1).  */
1264*a1acfa9bSespie 
1265*a1acfa9bSespie 				struct sysdep_string_desc *inmem_tab_entry =
1266*a1acfa9bSespie 				  (j == 0
1267*a1acfa9bSespie 				   ? inmem_orig_sysdep_tab
1268*a1acfa9bSespie 				   : inmem_trans_sysdep_tab)
1269*a1acfa9bSespie 				  + k;
1270*a1acfa9bSespie 
1271*a1acfa9bSespie 				if (W (domain->must_swap, p->sysdepref)
1272*a1acfa9bSespie 				    == SEGMENTS_END)
1273*a1acfa9bSespie 				  {
1274*a1acfa9bSespie 				    /* Only one static segment.  */
1275*a1acfa9bSespie 				    inmem_tab_entry->length =
1276*a1acfa9bSespie 				      W (domain->must_swap, p->segsize);
1277*a1acfa9bSespie 				    inmem_tab_entry->pointer = static_segments;
1278*a1acfa9bSespie 				  }
1279*a1acfa9bSespie 				else
1280*a1acfa9bSespie 				  {
1281*a1acfa9bSespie 				    inmem_tab_entry->pointer = mem;
1282*a1acfa9bSespie 
1283*a1acfa9bSespie 				    for (p = sysdep_string->segments;; p++)
1284*a1acfa9bSespie 				      {
1285*a1acfa9bSespie 					nls_uint32 segsize =
1286*a1acfa9bSespie 					  W (domain->must_swap, p->segsize);
1287*a1acfa9bSespie 					nls_uint32 sysdepref =
1288*a1acfa9bSespie 					  W (domain->must_swap, p->sysdepref);
1289*a1acfa9bSespie 					size_t n;
1290*a1acfa9bSespie 
1291*a1acfa9bSespie 					if (segsize > 0)
1292*a1acfa9bSespie 					  {
1293*a1acfa9bSespie 					    memcpy (mem, static_segments, segsize);
1294*a1acfa9bSespie 					    mem += segsize;
1295*a1acfa9bSespie 					    static_segments += segsize;
1296*a1acfa9bSespie 					  }
1297*a1acfa9bSespie 
1298*a1acfa9bSespie 					if (sysdepref == SEGMENTS_END)
1299*a1acfa9bSespie 					  break;
1300*a1acfa9bSespie 
1301*a1acfa9bSespie 					n = strlen (sysdep_segment_values[sysdepref]);
1302*a1acfa9bSespie 					memcpy (mem, sysdep_segment_values[sysdepref], n);
1303*a1acfa9bSespie 					mem += n;
1304*a1acfa9bSespie 				      }
1305*a1acfa9bSespie 
1306*a1acfa9bSespie 				    inmem_tab_entry->length =
1307*a1acfa9bSespie 				      mem - inmem_tab_entry->pointer;
1308*a1acfa9bSespie 				  }
1309*a1acfa9bSespie 			      }
1310*a1acfa9bSespie 
1311*a1acfa9bSespie 			    k++;
1312*a1acfa9bSespie 			  }
1313*a1acfa9bSespie 		      }
1314*a1acfa9bSespie 		    if (k != n_inmem_sysdep_strings)
1315*a1acfa9bSespie 		      abort ();
1316*a1acfa9bSespie 
1317*a1acfa9bSespie 		    /* Compute the augmented hash table.  */
1318*a1acfa9bSespie 		    for (i = 0; i < domain->hash_size; i++)
1319*a1acfa9bSespie 		      inmem_hash_tab[i] =
1320*a1acfa9bSespie 			W (domain->must_swap_hash_tab, domain->hash_tab[i]);
1321*a1acfa9bSespie 		    for (i = 0; i < n_inmem_sysdep_strings; i++)
1322*a1acfa9bSespie 		      {
1323*a1acfa9bSespie 			const char *msgid = inmem_orig_sysdep_tab[i].pointer;
1324*a1acfa9bSespie 			nls_uint32 hash_val = hash_string (msgid);
1325*a1acfa9bSespie 			nls_uint32 idx = hash_val % domain->hash_size;
1326*a1acfa9bSespie 			nls_uint32 incr =
1327*a1acfa9bSespie 			  1 + (hash_val % (domain->hash_size - 2));
1328*a1acfa9bSespie 
1329*a1acfa9bSespie 			for (;;)
1330*a1acfa9bSespie 			  {
1331*a1acfa9bSespie 			    if (inmem_hash_tab[idx] == 0)
1332*a1acfa9bSespie 			      {
1333*a1acfa9bSespie 				/* Hash table entry is empty.  Use it.  */
1334*a1acfa9bSespie 				inmem_hash_tab[idx] = 1 + domain->nstrings + i;
1335*a1acfa9bSespie 				break;
1336*a1acfa9bSespie 			      }
1337*a1acfa9bSespie 
1338*a1acfa9bSespie 			    if (idx >= domain->hash_size - incr)
1339*a1acfa9bSespie 			      idx -= domain->hash_size - incr;
1340*a1acfa9bSespie 			    else
1341*a1acfa9bSespie 			      idx += incr;
1342*a1acfa9bSespie 			  }
1343*a1acfa9bSespie 		      }
1344*a1acfa9bSespie 
1345*a1acfa9bSespie 		    domain->n_sysdep_strings = n_inmem_sysdep_strings;
1346*a1acfa9bSespie 		    domain->orig_sysdep_tab = inmem_orig_sysdep_tab;
1347*a1acfa9bSespie 		    domain->trans_sysdep_tab = inmem_trans_sysdep_tab;
1348*a1acfa9bSespie 
1349*a1acfa9bSespie 		    domain->hash_tab = inmem_hash_tab;
1350*a1acfa9bSespie 		    domain->must_swap_hash_tab = 0;
1351*a1acfa9bSespie 		  }
1352*a1acfa9bSespie 		else
1353*a1acfa9bSespie 		  {
1354*a1acfa9bSespie 		    domain->n_sysdep_strings = 0;
1355*a1acfa9bSespie 		    domain->orig_sysdep_tab = NULL;
1356*a1acfa9bSespie 		    domain->trans_sysdep_tab = NULL;
1357*a1acfa9bSespie 		  }
1358*a1acfa9bSespie 
1359*a1acfa9bSespie 		freea (sysdep_segment_values);
1360*a1acfa9bSespie 	      }
1361*a1acfa9bSespie 	    else
1362*a1acfa9bSespie 	      {
1363*a1acfa9bSespie 		domain->n_sysdep_strings = 0;
1364*a1acfa9bSespie 		domain->orig_sysdep_tab = NULL;
1365*a1acfa9bSespie 		domain->trans_sysdep_tab = NULL;
1366*a1acfa9bSespie 	      }
1367*a1acfa9bSespie 	  }
1368*a1acfa9bSespie 	  break;
1369*a1acfa9bSespie 	}
1370840175f0Skstailey       break;
1371840175f0Skstailey     default:
13723fb98d4aSespie       /* This is an invalid revision.  */
1373*a1acfa9bSespie     invalid:
1374*a1acfa9bSespie       /* This is an invalid .mo file.  */
1375*a1acfa9bSespie       if (domain->malloced)
1376*a1acfa9bSespie 	free (domain->malloced);
13773fb98d4aSespie #ifdef HAVE_MMAP
1378840175f0Skstailey       if (use_mmap)
13791cc83814Sespie 	munmap ((caddr_t) data, size);
1380840175f0Skstailey       else
1381840175f0Skstailey #endif
1382840175f0Skstailey 	free (data);
1383840175f0Skstailey       free (domain);
1384840175f0Skstailey       domain_file->data = NULL;
1385840175f0Skstailey       return;
1386840175f0Skstailey     }
1387840175f0Skstailey 
13883fb98d4aSespie   /* Now initialize the character set converter from the character set
13893fb98d4aSespie      the file is encoded with (found in the header entry) to the domain's
13903fb98d4aSespie      specified character set or the locale's character set.  */
13913fb98d4aSespie   nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding);
13923fb98d4aSespie 
13933fb98d4aSespie   /* Also look for a plural specification.  */
13943fb98d4aSespie   EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals);
1395840175f0Skstailey }
13961cc83814Sespie 
13971cc83814Sespie 
13981cc83814Sespie #ifdef _LIBC
13991cc83814Sespie void
14001cc83814Sespie internal_function
_nl_unload_domain(struct loaded_domain * domain)1401*a1acfa9bSespie _nl_unload_domain (struct loaded_domain *domain)
14021cc83814Sespie {
14033fb98d4aSespie   if (domain->plural != &__gettext_germanic_plural)
14043fb98d4aSespie     __gettext_free_exp (domain->plural);
14053fb98d4aSespie 
14063fb98d4aSespie   _nl_free_domain_conv (domain);
14073fb98d4aSespie 
1408*a1acfa9bSespie   if (domain->malloced)
1409*a1acfa9bSespie     free (domain->malloced);
1410*a1acfa9bSespie 
14113fb98d4aSespie # ifdef _POSIX_MAPPED_FILES
14121cc83814Sespie   if (domain->use_mmap)
14131cc83814Sespie     munmap ((caddr_t) domain->data, domain->mmap_size);
14141cc83814Sespie   else
14153fb98d4aSespie # endif	/* _POSIX_MAPPED_FILES */
14161cc83814Sespie     free ((void *) domain->data);
14171cc83814Sespie 
14181cc83814Sespie   free (domain);
14191cc83814Sespie }
14201cc83814Sespie #endif
1421