1 /* Load needed message catalogs.
2 Copyright (C) 1995-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 /* Tell glibc's <string.h> to provide a prototype for mempcpy().
21 This must come before <config.h> because <config.h> may include
22 <features.h>, and once <features.h> has been included, it's too late. */
24 # define _GNU_SOURCE 1
34 #include <sys/types.h>
39 # define alloca __builtin_alloca
40 # define HAVE_ALLOCA 1
42 # if defined HAVE_ALLOCA_H || defined _LIBC
58 #if defined HAVE_UNISTD_H || defined _LIBC
63 # include <langinfo.h>
67 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
68 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
69 # include <sys/mman.h>
76 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
79 #if defined HAVE_INTTYPES_H || defined _LIBC
80 # include <inttypes.h>
85 #include "hash-string.h"
86 #include "plural-exp.h"
89 # include "../locale/localeinfo.h"
92 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
93 Note that our fallback values need not be literal strings, because we don't
94 use them with preprocessor string concatenation. */
95 #if !defined PRId8 || PRI_MACROS_BROKEN
99 #if !defined PRIi8 || PRI_MACROS_BROKEN
103 #if !defined PRIo8 || PRI_MACROS_BROKEN
107 #if !defined PRIu8 || PRI_MACROS_BROKEN
111 #if !defined PRIx8 || PRI_MACROS_BROKEN
115 #if !defined PRIX8 || PRI_MACROS_BROKEN
119 #if !defined PRId16 || PRI_MACROS_BROKEN
123 #if !defined PRIi16 || PRI_MACROS_BROKEN
127 #if !defined PRIo16 || PRI_MACROS_BROKEN
131 #if !defined PRIu16 || PRI_MACROS_BROKEN
135 #if !defined PRIx16 || PRI_MACROS_BROKEN
139 #if !defined PRIX16 || PRI_MACROS_BROKEN
143 #if !defined PRId32 || PRI_MACROS_BROKEN
147 #if !defined PRIi32 || PRI_MACROS_BROKEN
151 #if !defined PRIo32 || PRI_MACROS_BROKEN
155 #if !defined PRIu32 || PRI_MACROS_BROKEN
159 #if !defined PRIx32 || PRI_MACROS_BROKEN
163 #if !defined PRIX32 || PRI_MACROS_BROKEN
167 #if !defined PRId64 || PRI_MACROS_BROKEN
169 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
171 #if !defined PRIi64 || PRI_MACROS_BROKEN
173 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
175 #if !defined PRIo64 || PRI_MACROS_BROKEN
177 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
179 #if !defined PRIu64 || PRI_MACROS_BROKEN
181 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
183 #if !defined PRIx64 || PRI_MACROS_BROKEN
185 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
187 #if !defined PRIX64 || PRI_MACROS_BROKEN
189 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
191 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
193 # define PRIdLEAST8 "d"
195 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
197 # define PRIiLEAST8 "i"
199 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
201 # define PRIoLEAST8 "o"
203 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
205 # define PRIuLEAST8 "u"
207 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
209 # define PRIxLEAST8 "x"
211 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
213 # define PRIXLEAST8 "X"
215 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
217 # define PRIdLEAST16 "d"
219 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
221 # define PRIiLEAST16 "i"
223 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
225 # define PRIoLEAST16 "o"
227 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
229 # define PRIuLEAST16 "u"
231 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
233 # define PRIxLEAST16 "x"
235 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
237 # define PRIXLEAST16 "X"
239 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
241 # define PRIdLEAST32 "d"
243 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
245 # define PRIiLEAST32 "i"
247 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
249 # define PRIoLEAST32 "o"
251 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
253 # define PRIuLEAST32 "u"
255 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
257 # define PRIxLEAST32 "x"
259 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
261 # define PRIXLEAST32 "X"
263 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
265 # define PRIdLEAST64 PRId64
267 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
269 # define PRIiLEAST64 PRIi64
271 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
273 # define PRIoLEAST64 PRIo64
275 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
277 # define PRIuLEAST64 PRIu64
279 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
281 # define PRIxLEAST64 PRIx64
283 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
285 # define PRIXLEAST64 PRIX64
287 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
289 # define PRIdFAST8 "d"
291 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
293 # define PRIiFAST8 "i"
295 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
297 # define PRIoFAST8 "o"
299 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
301 # define PRIuFAST8 "u"
303 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
305 # define PRIxFAST8 "x"
307 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
309 # define PRIXFAST8 "X"
311 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
313 # define PRIdFAST16 "d"
315 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
317 # define PRIiFAST16 "i"
319 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
321 # define PRIoFAST16 "o"
323 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
325 # define PRIuFAST16 "u"
327 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
329 # define PRIxFAST16 "x"
331 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
333 # define PRIXFAST16 "X"
335 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
337 # define PRIdFAST32 "d"
339 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
341 # define PRIiFAST32 "i"
343 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
345 # define PRIoFAST32 "o"
347 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
349 # define PRIuFAST32 "u"
351 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
353 # define PRIxFAST32 "x"
355 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
357 # define PRIXFAST32 "X"
359 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
361 # define PRIdFAST64 PRId64
363 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
365 # define PRIiFAST64 PRIi64
367 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
369 # define PRIoFAST64 PRIo64
371 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
373 # define PRIuFAST64 PRIu64
375 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
377 # define PRIxFAST64 PRIx64
379 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
381 # define PRIXFAST64 PRIX64
383 #if !defined PRIdMAX || PRI_MACROS_BROKEN
385 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
387 #if !defined PRIiMAX || PRI_MACROS_BROKEN
389 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
391 #if !defined PRIoMAX || PRI_MACROS_BROKEN
393 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
395 #if !defined PRIuMAX || PRI_MACROS_BROKEN
397 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
399 #if !defined PRIxMAX || PRI_MACROS_BROKEN
401 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
403 #if !defined PRIXMAX || PRI_MACROS_BROKEN
405 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
407 #if !defined PRIdPTR || PRI_MACROS_BROKEN
410 (sizeof (void *) == sizeof (long) ? "ld" : \
411 sizeof (void *) == sizeof (int) ? "d" : \
414 #if !defined PRIiPTR || PRI_MACROS_BROKEN
417 (sizeof (void *) == sizeof (long) ? "li" : \
418 sizeof (void *) == sizeof (int) ? "i" : \
421 #if !defined PRIoPTR || PRI_MACROS_BROKEN
424 (sizeof (void *) == sizeof (long) ? "lo" : \
425 sizeof (void *) == sizeof (int) ? "o" : \
428 #if !defined PRIuPTR || PRI_MACROS_BROKEN
431 (sizeof (void *) == sizeof (long) ? "lu" : \
432 sizeof (void *) == sizeof (int) ? "u" : \
435 #if !defined PRIxPTR || PRI_MACROS_BROKEN
438 (sizeof (void *) == sizeof (long) ? "lx" : \
439 sizeof (void *) == sizeof (int) ? "x" : \
442 #if !defined PRIXPTR || PRI_MACROS_BROKEN
445 (sizeof (void *) == sizeof (long) ? "lX" : \
446 sizeof (void *) == sizeof (int) ? "X" : \
450 /* @@ end of prolog @@ */
453 /* Rename the non ISO C functions. This is required by the standard
454 because some ISO C functions will require linking with this object
455 file and the name space must not be polluted. */
457 # define close __close
460 # define munmap __munmap
463 /* For those losing systems which don't have `alloca' we have to add
464 some additional code emulating it. */
466 # define freea(p) /* nothing */
468 # define alloca(n) malloc (n)
469 # define freea(p) free (p)
473 /* Prototypes for local functions. Needed to ensure compiler checking of
474 function argument counts despite of K&R C function definition syntax. */
475 static const char *get_sysdep_segment_value PARAMS ((const char *name));
478 /* We need a sign, whether a new catalog was loaded, which can be associated
479 with all translations. This is important if the translations are
480 cached by one of GCC's features. */
481 int _nl_msg_cat_cntr;
484 /* Expand a system dependent string segment. Return NULL if unsupported. */
486 get_sysdep_segment_value (name)
489 /* Test for an ISO C 99 section 7.8.1 format string directive.
491 P R I { d | i | o | u | x | X }
492 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
493 /* We don't use a table of 14 times 6 'const char *' strings here, because
494 data relocations cost startup time. */
495 if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I')
497 if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u'
498 || name[3] == 'x' || name[3] == 'X')
500 if (name[4] == '8' && name[5] == '\0')
516 if (name[4] == '1' && name[5] == '6' && name[6] == '\0')
532 if (name[4] == '3' && name[5] == '2' && name[6] == '\0')
548 if (name[4] == '6' && name[5] == '4' && name[6] == '\0')
564 if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A'
565 && name[7] == 'S' && name[8] == 'T')
567 if (name[9] == '8' && name[10] == '\0')
583 if (name[9] == '1' && name[10] == '6' && name[11] == '\0')
599 if (name[9] == '3' && name[10] == '2' && name[11] == '\0')
615 if (name[9] == '6' && name[10] == '4' && name[11] == '\0')
632 if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S'
635 if (name[8] == '8' && name[9] == '\0')
651 if (name[8] == '1' && name[9] == '6' && name[10] == '\0')
667 if (name[8] == '3' && name[9] == '2' && name[10] == '\0')
683 if (name[8] == '6' && name[9] == '4' && name[10] == '\0')
700 if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X'
717 if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R'
736 /* Other system dependent strings are not valid. */
740 /* Initialize the codeset dependent parts of an opened message catalog.
741 Return the header entry. */
744 _nl_init_domain_conv (domain_file, domain, domainbinding)
745 struct loaded_l10nfile *domain_file;
746 struct loaded_domain *domain;
747 struct binding *domainbinding;
749 /* Find out about the character set the file is encoded with.
750 This can be found (in textual form) in the entry "". If this
751 entry does not exist or if this does not contain the `charset='
752 information, we will assume the charset matches the one the
753 current locale and we don't have to perform any conversion. */
757 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
758 domain->codeset_cntr =
759 (domainbinding != NULL ? domainbinding->codeset_cntr : 0);
761 domain->conv = (__gconv_t) -1;
764 domain->conv = (iconv_t) -1;
767 domain->conv_tab = NULL;
769 /* Get the header entry. */
770 nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen);
772 if (nullentry != NULL)
774 #if defined _LIBC || HAVE_ICONV
775 const char *charsetstr;
777 charsetstr = strstr (nullentry, "charset=");
778 if (charsetstr != NULL)
782 const char *outcharset;
784 charsetstr += strlen ("charset=");
785 len = strcspn (charsetstr, " \t\n");
787 charset = (char *) alloca (len + 1);
788 # if defined _LIBC || HAVE_MEMPCPY
789 *((char *) mempcpy (charset, charsetstr, len)) = '\0';
791 memcpy (charset, charsetstr, len);
795 /* The output charset should normally be determined by the
796 locale. But sometimes the locale is not used or not correctly
797 set up, so we provide a possibility for the user to override
798 this. Moreover, the value specified through
799 bind_textdomain_codeset overrides both. */
800 if (domainbinding != NULL && domainbinding->codeset != NULL)
801 outcharset = domainbinding->codeset;
804 outcharset = getenv ("OUTPUT_CHARSET");
805 if (outcharset == NULL || outcharset[0] == '\0')
808 outcharset = _NL_CURRENT (LC_CTYPE, CODESET);
811 extern const char *locale_charset (void);
812 outcharset = locale_charset ();
819 /* We always want to use transliteration. */
820 outcharset = norm_add_slashes (outcharset, "TRANSLIT");
821 charset = norm_add_slashes (charset, NULL);
822 if (__gconv_open (outcharset, charset, &domain->conv,
825 domain->conv = (__gconv_t) -1;
828 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
829 we want to use transliteration. */
830 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
831 || _LIBICONV_VERSION >= 0x0105
832 len = strlen (outcharset);
833 if (len < 10 || strcmp (outcharset + len - 9, "/TRANSLIT") != 0)
835 char *tmp = (char *) alloca (len + 10 + 1);
836 memcpy (tmp, outcharset, len);
837 memcpy (tmp + len, "//TRANSLIT", 10 + 1);
841 domain->conv = iconv_open (outcharset, charset);
842 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
843 || _LIBICONV_VERSION >= 0x0105
851 #endif /* _LIBC || HAVE_ICONV */
857 /* Frees the codeset dependent parts of an opened message catalog. */
860 _nl_free_domain_conv (domain)
861 struct loaded_domain *domain;
863 if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1)
864 free (domain->conv_tab);
867 if (domain->conv != (__gconv_t) -1)
868 __gconv_close (domain->conv);
871 if (domain->conv != (iconv_t) -1)
872 iconv_close (domain->conv);
877 /* Load the message catalogs specified by FILENAME. If it is no valid
878 message catalog do nothing. */
881 _nl_load_domain (domain_file, domainbinding)
882 struct loaded_l10nfile *domain_file;
883 struct binding *domainbinding;
892 struct mo_file_header *data = (struct mo_file_header *) -1;
894 struct loaded_domain *domain;
896 const char *nullentry;
898 domain_file->decided = 1;
899 domain_file->data = NULL;
901 /* Note that it would be useless to store domainbinding in domain_file
902 because domainbinding might be == NULL now but != NULL later (after
903 a call to bind_textdomain_codeset). */
905 /* If the record does not represent a valid locale the FILENAME
906 might be NULL. This can happen when according to the given
907 specification the locale file name is different for XPG and CEN
909 if (domain_file->filename == NULL)
912 /* Try to open the addressed file. */
913 fd = open (domain_file->filename, O_RDONLY);
917 /* We must know about the size of the file. */
920 __builtin_expect (fstat64 (fd, &st) != 0, 0)
922 __builtin_expect (fstat (fd, &st) != 0, 0)
924 || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
925 || __builtin_expect (size < sizeof (struct mo_file_header), 0))
927 /* Something went wrong. */
933 /* Now we are ready to load the file. If mmap() is available we try
934 this first. If not available or it failed we try to load it. */
935 data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
938 if (__builtin_expect (data != (struct mo_file_header *) -1, 1))
940 /* mmap() call was successful. */
946 /* If the data is not yet available (i.e. mmap'ed) we try to load
948 if (data == (struct mo_file_header *) -1)
953 data = (struct mo_file_header *) malloc (size);
958 read_ptr = (char *) data;
961 long int nb = (long int) read (fd, read_ptr, to_read);
965 if (nb == -1 && errno == EINTR)
979 /* Using the magic number we can test whether it really is a message
981 if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED,
984 /* The magic number is wrong: not a message catalog file. */
987 munmap ((caddr_t) data, size);
994 domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
997 domain_file->data = domain;
999 domain->data = (char *) data;
1000 domain->use_mmap = use_mmap;
1001 domain->mmap_size = size;
1002 domain->must_swap = data->magic != _MAGIC;
1003 domain->malloced = NULL;
1005 /* Fill in the information about the available tables. */
1006 revision = W (domain->must_swap, data->revision);
1007 /* We support only the major revision 0. */
1008 switch (revision >> 16)
1011 domain->nstrings = W (domain->must_swap, data->nstrings);
1012 domain->orig_tab = (const struct string_desc *)
1013 ((char *) data + W (domain->must_swap, data->orig_tab_offset));
1014 domain->trans_tab = (const struct string_desc *)
1015 ((char *) data + W (domain->must_swap, data->trans_tab_offset));
1016 domain->hash_size = W (domain->must_swap, data->hash_tab_size);
1018 (domain->hash_size > 2
1019 ? (const nls_uint32 *)
1020 ((char *) data + W (domain->must_swap, data->hash_tab_offset))
1022 domain->must_swap_hash_tab = domain->must_swap;
1024 /* Now dispatch on the minor revision. */
1025 switch (revision & 0xffff)
1028 domain->n_sysdep_strings = 0;
1029 domain->orig_sysdep_tab = NULL;
1030 domain->trans_sysdep_tab = NULL;
1035 nls_uint32 n_sysdep_strings;
1037 if (domain->hash_tab == NULL)
1038 /* This is invalid. These minor revisions need a hash table. */
1042 W (domain->must_swap, data->n_sysdep_strings);
1043 if (n_sysdep_strings > 0)
1045 nls_uint32 n_sysdep_segments;
1046 const struct sysdep_segment *sysdep_segments;
1047 const char **sysdep_segment_values;
1048 const nls_uint32 *orig_sysdep_tab;
1049 const nls_uint32 *trans_sysdep_tab;
1052 struct sysdep_string_desc *inmem_orig_sysdep_tab;
1053 struct sysdep_string_desc *inmem_trans_sysdep_tab;
1054 nls_uint32 *inmem_hash_tab;
1057 /* Get the values of the system dependent segments. */
1059 W (domain->must_swap, data->n_sysdep_segments);
1060 sysdep_segments = (const struct sysdep_segment *)
1062 + W (domain->must_swap, data->sysdep_segments_offset));
1063 sysdep_segment_values =
1064 alloca (n_sysdep_segments * sizeof (const char *));
1065 for (i = 0; i < n_sysdep_segments; i++)
1069 + W (domain->must_swap, sysdep_segments[i].offset);
1070 nls_uint32 namelen =
1071 W (domain->must_swap, sysdep_segments[i].length);
1073 if (!(namelen > 0 && name[namelen - 1] == '\0'))
1075 freea (sysdep_segment_values);
1079 sysdep_segment_values[i] = get_sysdep_segment_value (name);
1082 orig_sysdep_tab = (const nls_uint32 *)
1084 + W (domain->must_swap, data->orig_sysdep_tab_offset));
1085 trans_sysdep_tab = (const nls_uint32 *)
1087 + W (domain->must_swap, data->trans_sysdep_tab_offset));
1089 /* Compute the amount of additional memory needed for the
1090 system dependent strings and the augmented hash table. */
1091 memneed = 2 * n_sysdep_strings
1092 * sizeof (struct sysdep_string_desc)
1093 + domain->hash_size * sizeof (nls_uint32);
1094 for (i = 0; i < 2 * n_sysdep_strings; i++)
1096 const struct sysdep_string *sysdep_string =
1097 (const struct sysdep_string *)
1099 + W (domain->must_swap,
1100 i < n_sysdep_strings
1101 ? orig_sysdep_tab[i]
1102 : trans_sysdep_tab[i - n_sysdep_strings]));
1104 const struct segment_pair *p = sysdep_string->segments;
1106 if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END)
1107 for (p = sysdep_string->segments;; p++)
1109 nls_uint32 sysdepref;
1111 need += W (domain->must_swap, p->segsize);
1113 sysdepref = W (domain->must_swap, p->sysdepref);
1114 if (sysdepref == SEGMENTS_END)
1117 if (sysdepref >= n_sysdep_segments)
1120 freea (sysdep_segment_values);
1124 need += strlen (sysdep_segment_values[sysdepref]);
1130 /* Allocate additional memory. */
1131 mem = (char *) malloc (memneed);
1135 domain->malloced = mem;
1136 inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem;
1137 mem += n_sysdep_strings * sizeof (struct sysdep_string_desc);
1138 inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem;
1139 mem += n_sysdep_strings * sizeof (struct sysdep_string_desc);
1140 inmem_hash_tab = (nls_uint32 *) mem;
1141 mem += domain->hash_size * sizeof (nls_uint32);
1143 /* Compute the system dependent strings. */
1144 for (i = 0; i < 2 * n_sysdep_strings; i++)
1146 const struct sysdep_string *sysdep_string =
1147 (const struct sysdep_string *)
1149 + W (domain->must_swap,
1150 i < n_sysdep_strings
1151 ? orig_sysdep_tab[i]
1152 : trans_sysdep_tab[i - n_sysdep_strings]));
1153 const char *static_segments =
1155 + W (domain->must_swap, sysdep_string->offset);
1156 const struct segment_pair *p = sysdep_string->segments;
1158 /* Concatenate the segments, and fill
1159 inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and
1160 inmem_trans_sysdep_tab[i-n_sysdep_strings] (for
1161 i >= n_sysdep_strings). */
1163 if (W (domain->must_swap, p->sysdepref) == SEGMENTS_END)
1165 /* Only one static segment. */
1166 inmem_orig_sysdep_tab[i].length =
1167 W (domain->must_swap, p->segsize);
1168 inmem_orig_sysdep_tab[i].pointer = static_segments;
1172 inmem_orig_sysdep_tab[i].pointer = mem;
1174 for (p = sysdep_string->segments;; p++)
1176 nls_uint32 segsize =
1177 W (domain->must_swap, p->segsize);
1178 nls_uint32 sysdepref =
1179 W (domain->must_swap, p->sysdepref);
1184 memcpy (mem, static_segments, segsize);
1186 static_segments += segsize;
1189 if (sysdepref == SEGMENTS_END)
1192 n = strlen (sysdep_segment_values[sysdepref]);
1193 memcpy (mem, sysdep_segment_values[sysdepref], n);
1197 inmem_orig_sysdep_tab[i].length =
1198 mem - inmem_orig_sysdep_tab[i].pointer;
1202 /* Compute the augmented hash table. */
1203 for (i = 0; i < domain->hash_size; i++)
1205 W (domain->must_swap_hash_tab, domain->hash_tab[i]);
1206 for (i = 0; i < n_sysdep_strings; i++)
1208 const char *msgid = inmem_orig_sysdep_tab[i].pointer;
1209 nls_uint32 hash_val = hash_string (msgid);
1210 nls_uint32 idx = hash_val % domain->hash_size;
1211 nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2));
1215 if (inmem_hash_tab[idx] == 0)
1217 /* Hash table entry is empty. Use it. */
1218 inmem_hash_tab[idx] = 1 + domain->nstrings + i;
1222 if (idx >= domain->hash_size - incr)
1223 idx -= domain->hash_size - incr;
1229 freea (sysdep_segment_values);
1231 domain->n_sysdep_strings = n_sysdep_strings;
1232 domain->orig_sysdep_tab = inmem_orig_sysdep_tab;
1233 domain->trans_sysdep_tab = inmem_trans_sysdep_tab;
1235 domain->hash_tab = inmem_hash_tab;
1236 domain->must_swap_hash_tab = 0;
1240 domain->n_sysdep_strings = 0;
1241 domain->orig_sysdep_tab = NULL;
1242 domain->trans_sysdep_tab = NULL;
1249 /* This is an invalid revision. */
1251 /* This is an invalid .mo file. */
1252 if (domain->malloced)
1253 free (domain->malloced);
1256 munmap ((caddr_t) data, size);
1261 domain_file->data = NULL;
1265 /* Now initialize the character set converter from the character set
1266 the file is encoded with (found in the header entry) to the domain's
1267 specified character set or the locale's character set. */
1268 nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding);
1270 /* Also look for a plural specification. */
1271 EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals);
1278 _nl_unload_domain (domain)
1279 struct loaded_domain *domain;
1281 if (domain->plural != &__gettext_germanic_plural)
1282 __gettext_free_exp (domain->plural);
1284 _nl_free_domain_conv (domain);
1286 if (domain->malloced)
1287 free (domain->malloced);
1289 # ifdef _POSIX_MAPPED_FILES
1290 if (domain->use_mmap)
1291 munmap ((caddr_t) domain->data, domain->mmap_size);
1293 # endif /* _POSIX_MAPPED_FILES */
1294 free ((void *) domain->data);