1 /* loadmsgcat.c - Load needed message catalogs. */
3 /* Copyright (C) 1995-1999, 2000-2003, 2005-2009 Free Software Foundation, Inc.
5 This file is part of GNU Bash.
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
21 /* Tell glibc's <string.h> to provide a prototype for mempcpy().
22 This must come before <config.h> because <config.h> may include
23 <features.h>, and once <features.h> has been included, it's too late. */
25 # define _GNU_SOURCE 1
35 #include <sys/types.h>
40 # define alloca __builtin_alloca
41 # define HAVE_ALLOCA 1
45 # define alloca _alloca
47 # if defined HAVE_ALLOCA_H || defined _LIBC
64 #if defined HAVE_UNISTD_H || defined _LIBC
69 # include <langinfo.h>
73 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
74 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
75 # include <sys/mman.h>
82 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
85 #if defined HAVE_INTTYPES_H || defined _LIBC
86 # include <inttypes.h>
91 #include "hash-string.h"
92 #include "plural-exp.h"
95 # include "../locale/localeinfo.h"
98 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
99 Note that our fallback values need not be literal strings, because we don't
100 use them with preprocessor string concatenation. */
101 #if !defined PRId8 || PRI_MACROS_BROKEN
105 #if !defined PRIi8 || PRI_MACROS_BROKEN
109 #if !defined PRIo8 || PRI_MACROS_BROKEN
113 #if !defined PRIu8 || PRI_MACROS_BROKEN
117 #if !defined PRIx8 || PRI_MACROS_BROKEN
121 #if !defined PRIX8 || PRI_MACROS_BROKEN
125 #if !defined PRId16 || PRI_MACROS_BROKEN
129 #if !defined PRIi16 || PRI_MACROS_BROKEN
133 #if !defined PRIo16 || PRI_MACROS_BROKEN
137 #if !defined PRIu16 || PRI_MACROS_BROKEN
141 #if !defined PRIx16 || PRI_MACROS_BROKEN
145 #if !defined PRIX16 || PRI_MACROS_BROKEN
149 #if !defined PRId32 || PRI_MACROS_BROKEN
153 #if !defined PRIi32 || PRI_MACROS_BROKEN
157 #if !defined PRIo32 || PRI_MACROS_BROKEN
161 #if !defined PRIu32 || PRI_MACROS_BROKEN
165 #if !defined PRIx32 || PRI_MACROS_BROKEN
169 #if !defined PRIX32 || PRI_MACROS_BROKEN
173 #if !defined PRId64 || PRI_MACROS_BROKEN
175 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
177 #if !defined PRIi64 || PRI_MACROS_BROKEN
179 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
181 #if !defined PRIo64 || PRI_MACROS_BROKEN
183 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
185 #if !defined PRIu64 || PRI_MACROS_BROKEN
187 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
189 #if !defined PRIx64 || PRI_MACROS_BROKEN
191 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
193 #if !defined PRIX64 || PRI_MACROS_BROKEN
195 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
197 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
199 # define PRIdLEAST8 "d"
201 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
203 # define PRIiLEAST8 "i"
205 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
207 # define PRIoLEAST8 "o"
209 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
211 # define PRIuLEAST8 "u"
213 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
215 # define PRIxLEAST8 "x"
217 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
219 # define PRIXLEAST8 "X"
221 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
223 # define PRIdLEAST16 "d"
225 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
227 # define PRIiLEAST16 "i"
229 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
231 # define PRIoLEAST16 "o"
233 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
235 # define PRIuLEAST16 "u"
237 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
239 # define PRIxLEAST16 "x"
241 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
243 # define PRIXLEAST16 "X"
245 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
247 # define PRIdLEAST32 "d"
249 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
251 # define PRIiLEAST32 "i"
253 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
255 # define PRIoLEAST32 "o"
257 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
259 # define PRIuLEAST32 "u"
261 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
263 # define PRIxLEAST32 "x"
265 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
267 # define PRIXLEAST32 "X"
269 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
271 # define PRIdLEAST64 PRId64
273 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
275 # define PRIiLEAST64 PRIi64
277 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
279 # define PRIoLEAST64 PRIo64
281 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
283 # define PRIuLEAST64 PRIu64
285 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
287 # define PRIxLEAST64 PRIx64
289 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
291 # define PRIXLEAST64 PRIX64
293 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
295 # define PRIdFAST8 "d"
297 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
299 # define PRIiFAST8 "i"
301 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
303 # define PRIoFAST8 "o"
305 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
307 # define PRIuFAST8 "u"
309 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
311 # define PRIxFAST8 "x"
313 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
315 # define PRIXFAST8 "X"
317 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
319 # define PRIdFAST16 "d"
321 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
323 # define PRIiFAST16 "i"
325 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
327 # define PRIoFAST16 "o"
329 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
331 # define PRIuFAST16 "u"
333 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
335 # define PRIxFAST16 "x"
337 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
339 # define PRIXFAST16 "X"
341 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
343 # define PRIdFAST32 "d"
345 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
347 # define PRIiFAST32 "i"
349 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
351 # define PRIoFAST32 "o"
353 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
355 # define PRIuFAST32 "u"
357 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
359 # define PRIxFAST32 "x"
361 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
363 # define PRIXFAST32 "X"
365 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
367 # define PRIdFAST64 PRId64
369 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
371 # define PRIiFAST64 PRIi64
373 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
375 # define PRIoFAST64 PRIo64
377 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
379 # define PRIuFAST64 PRIu64
381 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
383 # define PRIxFAST64 PRIx64
385 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
387 # define PRIXFAST64 PRIX64
389 #if !defined PRIdMAX || PRI_MACROS_BROKEN
391 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
393 #if !defined PRIiMAX || PRI_MACROS_BROKEN
395 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
397 #if !defined PRIoMAX || PRI_MACROS_BROKEN
399 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
401 #if !defined PRIuMAX || PRI_MACROS_BROKEN
403 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
405 #if !defined PRIxMAX || PRI_MACROS_BROKEN
407 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
409 #if !defined PRIXMAX || PRI_MACROS_BROKEN
411 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
413 #if !defined PRIdPTR || PRI_MACROS_BROKEN
416 (sizeof (void *) == sizeof (long) ? "ld" : \
417 sizeof (void *) == sizeof (int) ? "d" : \
420 #if !defined PRIiPTR || PRI_MACROS_BROKEN
423 (sizeof (void *) == sizeof (long) ? "li" : \
424 sizeof (void *) == sizeof (int) ? "i" : \
427 #if !defined PRIoPTR || PRI_MACROS_BROKEN
430 (sizeof (void *) == sizeof (long) ? "lo" : \
431 sizeof (void *) == sizeof (int) ? "o" : \
434 #if !defined PRIuPTR || PRI_MACROS_BROKEN
437 (sizeof (void *) == sizeof (long) ? "lu" : \
438 sizeof (void *) == sizeof (int) ? "u" : \
441 #if !defined PRIxPTR || PRI_MACROS_BROKEN
444 (sizeof (void *) == sizeof (long) ? "lx" : \
445 sizeof (void *) == sizeof (int) ? "x" : \
448 #if !defined PRIXPTR || PRI_MACROS_BROKEN
451 (sizeof (void *) == sizeof (long) ? "lX" : \
452 sizeof (void *) == sizeof (int) ? "X" : \
456 /* @@ end of prolog @@ */
459 /* Rename the non ISO C functions. This is required by the standard
460 because some ISO C functions will require linking with this object
461 file and the name space must not be polluted. */
463 # define close __close
466 # define munmap __munmap
469 /* For those losing systems which don't have `alloca' we have to add
470 some additional code emulating it. */
472 # define freea(p) /* nothing */
474 # define alloca(n) malloc (n)
475 # define freea(p) free (p)
478 /* For systems that distinguish between text and binary I/O.
479 O_BINARY is usually declared in <fcntl.h>. */
480 #if !defined O_BINARY && defined _O_BINARY
481 /* For MSC-compatible compilers. */
482 # define O_BINARY _O_BINARY
483 # define O_TEXT _O_TEXT
486 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
490 /* On reasonable systems, binary I/O is the default. */
496 /* Prototypes for local functions. Needed to ensure compiler checking of
497 function argument counts despite of K&R C function definition syntax. */
498 static const char *get_sysdep_segment_value
PARAMS ((const char *name
));
501 /* We need a sign, whether a new catalog was loaded, which can be associated
502 with all translations. This is important if the translations are
503 cached by one of GCC's features. */
504 int _nl_msg_cat_cntr
;
507 /* Expand a system dependent string segment. Return NULL if unsupported. */
509 get_sysdep_segment_value (name
)
512 /* Test for an ISO C 99 section 7.8.1 format string directive.
514 P R I { d | i | o | u | x | X }
515 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
516 /* We don't use a table of 14 times 6 'const char *' strings here, because
517 data relocations cost startup time. */
518 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
520 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
521 || name
[3] == 'x' || name
[3] == 'X')
523 if (name
[4] == '8' && name
[5] == '\0')
539 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
555 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
571 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
587 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
588 && name
[7] == 'S' && name
[8] == 'T')
590 if (name
[9] == '8' && name
[10] == '\0')
606 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
622 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
638 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
655 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
658 if (name
[8] == '8' && name
[9] == '\0')
674 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
690 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
706 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
723 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
740 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
759 /* Other system dependent strings are not valid. */
763 /* Initialize the codeset dependent parts of an opened message catalog.
764 Return the header entry. */
767 _nl_init_domain_conv (domain_file
, domain
, domainbinding
)
768 struct loaded_l10nfile
*domain_file
;
769 struct loaded_domain
*domain
;
770 struct binding
*domainbinding
;
772 /* Find out about the character set the file is encoded with.
773 This can be found (in textual form) in the entry "". If this
774 entry does not exist or if this does not contain the `charset='
775 information, we will assume the charset matches the one the
776 current locale and we don't have to perform any conversion. */
780 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
781 domain
->codeset_cntr
=
782 (domainbinding
!= NULL
? domainbinding
->codeset_cntr
: 0);
784 domain
->conv
= (__gconv_t
) -1;
787 domain
->conv
= (iconv_t
) -1;
790 domain
->conv_tab
= NULL
;
792 /* Get the header entry. */
793 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", &nullentrylen
);
795 if (nullentry
!= NULL
)
797 #if defined _LIBC || HAVE_ICONV
798 const char *charsetstr
;
800 charsetstr
= strstr (nullentry
, "charset=");
801 if (charsetstr
!= NULL
)
805 const char *outcharset
;
807 charsetstr
+= strlen ("charset=");
808 len
= strcspn (charsetstr
, " \t\n");
810 charset
= (char *) alloca (len
+ 1);
811 # if defined _LIBC || HAVE_MEMPCPY
812 *((char *) mempcpy (charset
, charsetstr
, len
)) = '\0';
814 memcpy (charset
, charsetstr
, len
);
818 /* The output charset should normally be determined by the
819 locale. But sometimes the locale is not used or not correctly
820 set up, so we provide a possibility for the user to override
821 this. Moreover, the value specified through
822 bind_textdomain_codeset overrides both. */
823 if (domainbinding
!= NULL
&& domainbinding
->codeset
!= NULL
)
824 outcharset
= domainbinding
->codeset
;
827 outcharset
= getenv ("OUTPUT_CHARSET");
828 if (outcharset
== NULL
|| outcharset
[0] == '\0')
831 outcharset
= _NL_CURRENT (LC_CTYPE
, CODESET
);
834 extern const char *locale_charset
PARAMS ((void));
835 outcharset
= locale_charset ();
842 /* We always want to use transliteration. */
843 outcharset
= norm_add_slashes (outcharset
, "TRANSLIT");
844 charset
= norm_add_slashes (charset
, NULL
);
845 if (__gconv_open (outcharset
, charset
, &domain
->conv
,
848 domain
->conv
= (__gconv_t
) -1;
851 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
852 we want to use transliteration. */
853 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
854 || _LIBICONV_VERSION >= 0x0105
855 if (strchr (outcharset
, '/') == NULL
)
859 len
= strlen (outcharset
);
860 tmp
= (char *) alloca (len
+ 10 + 1);
861 memcpy (tmp
, outcharset
, len
);
862 memcpy (tmp
+ len
, "//TRANSLIT", 10 + 1);
865 domain
->conv
= iconv_open (outcharset
, charset
);
871 domain
->conv
= iconv_open (outcharset
, charset
);
877 #endif /* _LIBC || HAVE_ICONV */
883 /* Frees the codeset dependent parts of an opened message catalog. */
886 _nl_free_domain_conv (domain
)
887 struct loaded_domain
*domain
;
889 if (domain
->conv_tab
!= NULL
&& domain
->conv_tab
!= (char **) -1)
890 free (domain
->conv_tab
);
893 if (domain
->conv
!= (__gconv_t
) -1)
894 __gconv_close (domain
->conv
);
897 if (domain
->conv
!= (iconv_t
) -1)
898 iconv_close (domain
->conv
);
903 /* Load the message catalogs specified by FILENAME. If it is no valid
904 message catalog do nothing. */
907 _nl_load_domain (domain_file
, domainbinding
)
908 struct loaded_l10nfile
*domain_file
;
909 struct binding
*domainbinding
;
918 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
920 struct loaded_domain
*domain
;
922 const char *nullentry
;
924 domain_file
->decided
= 1;
925 domain_file
->data
= NULL
;
927 /* Note that it would be useless to store domainbinding in domain_file
928 because domainbinding might be == NULL now but != NULL later (after
929 a call to bind_textdomain_codeset). */
931 /* If the record does not represent a valid locale the FILENAME
932 might be NULL. This can happen when according to the given
933 specification the locale file name is different for XPG and CEN
935 if (domain_file
->filename
== NULL
)
938 /* Try to open the addressed file. */
939 fd
= open (domain_file
->filename
, O_RDONLY
| O_BINARY
);
943 /* We must know about the size of the file. */
946 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
948 __builtin_expect (fstat (fd
, &st
) != 0, 0)
950 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
951 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
953 /* Something went wrong. */
959 /* Now we are ready to load the file. If mmap() is available we try
960 this first. If not available or it failed we try to load it. */
961 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
964 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
966 /* mmap() call was successful. */
972 /* If the data is not yet available (i.e. mmap'ed) we try to load
974 if (data
== (struct mo_file_header
*) -1)
979 data
= (struct mo_file_header
*) malloc (size
);
984 read_ptr
= (char *) data
;
987 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
991 if (nb
== -1 && errno
== EINTR
)
1000 while (to_read
> 0);
1005 /* Using the magic number we can test whether it really is a message
1007 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
1010 /* The magic number is wrong: not a message catalog file. */
1013 munmap ((caddr_t
) data
, size
);
1020 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
1023 domain_file
->data
= domain
;
1025 domain
->data
= (char *) data
;
1026 domain
->use_mmap
= use_mmap
;
1027 domain
->mmap_size
= size
;
1028 domain
->must_swap
= data
->magic
!= _MAGIC
;
1029 domain
->malloced
= NULL
;
1031 /* Fill in the information about the available tables. */
1032 revision
= W (domain
->must_swap
, data
->revision
);
1033 /* We support only the major revision 0. */
1034 switch (revision
>> 16)
1037 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
1038 domain
->orig_tab
= (const struct string_desc
*)
1039 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
1040 domain
->trans_tab
= (const struct string_desc
*)
1041 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
1042 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
1044 (domain
->hash_size
> 2
1045 ? (const nls_uint32
*)
1046 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
1048 domain
->must_swap_hash_tab
= domain
->must_swap
;
1050 /* Now dispatch on the minor revision. */
1051 switch (revision
& 0xffff)
1054 domain
->n_sysdep_strings
= 0;
1055 domain
->orig_sysdep_tab
= NULL
;
1056 domain
->trans_sysdep_tab
= NULL
;
1061 nls_uint32 n_sysdep_strings
;
1063 if (domain
->hash_tab
== NULL
)
1064 /* This is invalid. These minor revisions need a hash table. */
1068 W (domain
->must_swap
, data
->n_sysdep_strings
);
1069 if (n_sysdep_strings
> 0)
1071 nls_uint32 n_sysdep_segments
;
1072 const struct sysdep_segment
*sysdep_segments
;
1073 const char **sysdep_segment_values
;
1074 const nls_uint32
*orig_sysdep_tab
;
1075 const nls_uint32
*trans_sysdep_tab
;
1078 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
1079 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
1080 nls_uint32
*inmem_hash_tab
;
1083 /* Get the values of the system dependent segments. */
1085 W (domain
->must_swap
, data
->n_sysdep_segments
);
1086 sysdep_segments
= (const struct sysdep_segment
*)
1088 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
1089 sysdep_segment_values
=
1090 alloca (n_sysdep_segments
* sizeof (const char *));
1091 for (i
= 0; i
< n_sysdep_segments
; i
++)
1095 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
1096 nls_uint32 namelen
=
1097 W (domain
->must_swap
, sysdep_segments
[i
].length
);
1099 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
1101 freea (sysdep_segment_values
);
1105 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
1108 orig_sysdep_tab
= (const nls_uint32
*)
1110 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1111 trans_sysdep_tab
= (const nls_uint32
*)
1113 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1115 /* Compute the amount of additional memory needed for the
1116 system dependent strings and the augmented hash table. */
1117 memneed
= 2 * n_sysdep_strings
1118 * sizeof (struct sysdep_string_desc
)
1119 + domain
->hash_size
* sizeof (nls_uint32
);
1120 for (i
= 0; i
< 2 * n_sysdep_strings
; i
++)
1122 const struct sysdep_string
*sysdep_string
=
1123 (const struct sysdep_string
*)
1125 + W (domain
->must_swap
,
1126 i
< n_sysdep_strings
1127 ? orig_sysdep_tab
[i
]
1128 : trans_sysdep_tab
[i
- n_sysdep_strings
]));
1130 const struct segment_pair
*p
= sysdep_string
->segments
;
1132 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1133 for (p
= sysdep_string
->segments
;; p
++)
1135 nls_uint32 sysdepref
;
1137 need
+= W (domain
->must_swap
, p
->segsize
);
1139 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1140 if (sysdepref
== SEGMENTS_END
)
1143 if (sysdepref
>= n_sysdep_segments
)
1146 freea (sysdep_segment_values
);
1150 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1156 /* Allocate additional memory. */
1157 mem
= (char *) malloc (memneed
);
1161 domain
->malloced
= mem
;
1162 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1163 mem
+= n_sysdep_strings
* sizeof (struct sysdep_string_desc
);
1164 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1165 mem
+= n_sysdep_strings
* sizeof (struct sysdep_string_desc
);
1166 inmem_hash_tab
= (nls_uint32
*) mem
;
1167 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1169 /* Compute the system dependent strings. */
1170 for (i
= 0; i
< 2 * n_sysdep_strings
; i
++)
1172 const struct sysdep_string
*sysdep_string
=
1173 (const struct sysdep_string
*)
1175 + W (domain
->must_swap
,
1176 i
< n_sysdep_strings
1177 ? orig_sysdep_tab
[i
]
1178 : trans_sysdep_tab
[i
- n_sysdep_strings
]));
1179 const char *static_segments
=
1181 + W (domain
->must_swap
, sysdep_string
->offset
);
1182 const struct segment_pair
*p
= sysdep_string
->segments
;
1184 /* Concatenate the segments, and fill
1185 inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and
1186 inmem_trans_sysdep_tab[i-n_sysdep_strings] (for
1187 i >= n_sysdep_strings). */
1189 if (W (domain
->must_swap
, p
->sysdepref
) == SEGMENTS_END
)
1191 /* Only one static segment. */
1192 inmem_orig_sysdep_tab
[i
].length
=
1193 W (domain
->must_swap
, p
->segsize
);
1194 inmem_orig_sysdep_tab
[i
].pointer
= static_segments
;
1198 inmem_orig_sysdep_tab
[i
].pointer
= mem
;
1200 for (p
= sysdep_string
->segments
;; p
++)
1202 nls_uint32 segsize
=
1203 W (domain
->must_swap
, p
->segsize
);
1204 nls_uint32 sysdepref
=
1205 W (domain
->must_swap
, p
->sysdepref
);
1210 memcpy (mem
, static_segments
, segsize
);
1212 static_segments
+= segsize
;
1215 if (sysdepref
== SEGMENTS_END
)
1218 n
= strlen (sysdep_segment_values
[sysdepref
]);
1219 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1223 inmem_orig_sysdep_tab
[i
].length
=
1224 mem
- inmem_orig_sysdep_tab
[i
].pointer
;
1228 /* Compute the augmented hash table. */
1229 for (i
= 0; i
< domain
->hash_size
; i
++)
1231 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1232 for (i
= 0; i
< n_sysdep_strings
; i
++)
1234 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1235 nls_uint32 hash_val
= hash_string (msgid
);
1236 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1237 nls_uint32 incr
= 1 + (hash_val
% (domain
->hash_size
- 2));
1241 if (inmem_hash_tab
[idx
] == 0)
1243 /* Hash table entry is empty. Use it. */
1244 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1248 if (idx
>= domain
->hash_size
- incr
)
1249 idx
-= domain
->hash_size
- incr
;
1255 freea (sysdep_segment_values
);
1257 domain
->n_sysdep_strings
= n_sysdep_strings
;
1258 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1259 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1261 domain
->hash_tab
= inmem_hash_tab
;
1262 domain
->must_swap_hash_tab
= 0;
1266 domain
->n_sysdep_strings
= 0;
1267 domain
->orig_sysdep_tab
= NULL
;
1268 domain
->trans_sysdep_tab
= NULL
;
1275 /* This is an invalid revision. */
1277 /* This is an invalid .mo file. */
1278 if (domain
->malloced
)
1279 free (domain
->malloced
);
1282 munmap ((caddr_t
) data
, size
);
1287 domain_file
->data
= NULL
;
1291 /* Now initialize the character set converter from the character set
1292 the file is encoded with (found in the header entry) to the domain's
1293 specified character set or the locale's character set. */
1294 nullentry
= _nl_init_domain_conv (domain_file
, domain
, domainbinding
);
1296 /* Also look for a plural specification. */
1297 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1304 _nl_unload_domain (domain
)
1305 struct loaded_domain
*domain
;
1307 if (domain
->plural
!= &__gettext_germanic_plural
)
1308 __gettext_free_exp (domain
->plural
);
1310 _nl_free_domain_conv (domain
);
1312 if (domain
->malloced
)
1313 free (domain
->malloced
);
1315 # ifdef _POSIX_MAPPED_FILES
1316 if (domain
->use_mmap
)
1317 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1319 # endif /* _POSIX_MAPPED_FILES */
1320 free ((void *) domain
->data
);