1 /* Load needed message catalogs.
2 Copyright (C) 1995-1999, 2000-2002 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 /* Tell glibc's <string.h> to provide a prototype for mempcpy().
20 This must come before <config.h> because <config.h> may include
21 <features.h>, and once <features.h> has been included, it's too late. */
23 # define _GNU_SOURCE 1
33 #include <sys/types.h>
37 # define alloca __builtin_alloca
38 # define HAVE_ALLOCA 1
40 # if defined HAVE_ALLOCA_H || defined _LIBC
56 #if defined HAVE_UNISTD_H || defined _LIBC
61 # include <langinfo.h>
65 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
66 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
67 # include <sys/mman.h>
74 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
77 #if defined HAVE_INTTYPES_H || defined _LIBC
78 # include <inttypes.h>
83 #include "hash-string.h"
84 #include "plural-exp.h"
87 # include "../locale/localeinfo.h"
90 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
91 Note that our fallback values need not be literal strings, because we don't
92 use them with preprocessor string concatenation. */
93 #if !defined PRId8 || PRI_MACROS_BROKEN
97 #if !defined PRIi8 || PRI_MACROS_BROKEN
101 #if !defined PRIo8 || PRI_MACROS_BROKEN
105 #if !defined PRIu8 || PRI_MACROS_BROKEN
109 #if !defined PRIx8 || PRI_MACROS_BROKEN
113 #if !defined PRIX8 || PRI_MACROS_BROKEN
117 #if !defined PRId16 || PRI_MACROS_BROKEN
121 #if !defined PRIi16 || PRI_MACROS_BROKEN
125 #if !defined PRIo16 || PRI_MACROS_BROKEN
129 #if !defined PRIu16 || PRI_MACROS_BROKEN
133 #if !defined PRIx16 || PRI_MACROS_BROKEN
137 #if !defined PRIX16 || PRI_MACROS_BROKEN
141 #if !defined PRId32 || PRI_MACROS_BROKEN
145 #if !defined PRIi32 || PRI_MACROS_BROKEN
149 #if !defined PRIo32 || PRI_MACROS_BROKEN
153 #if !defined PRIu32 || PRI_MACROS_BROKEN
157 #if !defined PRIx32 || PRI_MACROS_BROKEN
161 #if !defined PRIX32 || PRI_MACROS_BROKEN
165 #if !defined PRId64 || PRI_MACROS_BROKEN
167 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
169 #if !defined PRIi64 || PRI_MACROS_BROKEN
171 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
173 #if !defined PRIo64 || PRI_MACROS_BROKEN
175 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
177 #if !defined PRIu64 || PRI_MACROS_BROKEN
179 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
181 #if !defined PRIx64 || PRI_MACROS_BROKEN
183 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
185 #if !defined PRIX64 || PRI_MACROS_BROKEN
187 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
189 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
191 # define PRIdLEAST8 "d"
193 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
195 # define PRIiLEAST8 "i"
197 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
199 # define PRIoLEAST8 "o"
201 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
203 # define PRIuLEAST8 "u"
205 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
207 # define PRIxLEAST8 "x"
209 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
211 # define PRIXLEAST8 "X"
213 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
215 # define PRIdLEAST16 "d"
217 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
219 # define PRIiLEAST16 "i"
221 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
223 # define PRIoLEAST16 "o"
225 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
227 # define PRIuLEAST16 "u"
229 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
231 # define PRIxLEAST16 "x"
233 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
235 # define PRIXLEAST16 "X"
237 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
239 # define PRIdLEAST32 "d"
241 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
243 # define PRIiLEAST32 "i"
245 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
247 # define PRIoLEAST32 "o"
249 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
251 # define PRIuLEAST32 "u"
253 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
255 # define PRIxLEAST32 "x"
257 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
259 # define PRIXLEAST32 "X"
261 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
263 # define PRIdLEAST64 PRId64
265 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
267 # define PRIiLEAST64 PRIi64
269 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
271 # define PRIoLEAST64 PRIo64
273 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
275 # define PRIuLEAST64 PRIu64
277 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
279 # define PRIxLEAST64 PRIx64
281 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
283 # define PRIXLEAST64 PRIX64
285 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
287 # define PRIdFAST8 "d"
289 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
291 # define PRIiFAST8 "i"
293 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
295 # define PRIoFAST8 "o"
297 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
299 # define PRIuFAST8 "u"
301 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
303 # define PRIxFAST8 "x"
305 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
307 # define PRIXFAST8 "X"
309 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
311 # define PRIdFAST16 "d"
313 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
315 # define PRIiFAST16 "i"
317 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
319 # define PRIoFAST16 "o"
321 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
323 # define PRIuFAST16 "u"
325 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
327 # define PRIxFAST16 "x"
329 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
331 # define PRIXFAST16 "X"
333 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
335 # define PRIdFAST32 "d"
337 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
339 # define PRIiFAST32 "i"
341 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
343 # define PRIoFAST32 "o"
345 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
347 # define PRIuFAST32 "u"
349 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
351 # define PRIxFAST32 "x"
353 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
355 # define PRIXFAST32 "X"
357 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
359 # define PRIdFAST64 PRId64
361 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
363 # define PRIiFAST64 PRIi64
365 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
367 # define PRIoFAST64 PRIo64
369 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
371 # define PRIuFAST64 PRIu64
373 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
375 # define PRIxFAST64 PRIx64
377 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
379 # define PRIXFAST64 PRIX64
381 #if !defined PRIdMAX || PRI_MACROS_BROKEN
383 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
385 #if !defined PRIiMAX || PRI_MACROS_BROKEN
387 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
389 #if !defined PRIoMAX || PRI_MACROS_BROKEN
391 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
393 #if !defined PRIuMAX || PRI_MACROS_BROKEN
395 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
397 #if !defined PRIxMAX || PRI_MACROS_BROKEN
399 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
401 #if !defined PRIXMAX || PRI_MACROS_BROKEN
403 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
405 #if !defined PRIdPTR || PRI_MACROS_BROKEN
408 (sizeof (void *) == sizeof (long) ? "ld" : \
409 sizeof (void *) == sizeof (int) ? "d" : \
412 #if !defined PRIiPTR || PRI_MACROS_BROKEN
415 (sizeof (void *) == sizeof (long) ? "li" : \
416 sizeof (void *) == sizeof (int) ? "i" : \
419 #if !defined PRIoPTR || PRI_MACROS_BROKEN
422 (sizeof (void *) == sizeof (long) ? "lo" : \
423 sizeof (void *) == sizeof (int) ? "o" : \
426 #if !defined PRIuPTR || PRI_MACROS_BROKEN
429 (sizeof (void *) == sizeof (long) ? "lu" : \
430 sizeof (void *) == sizeof (int) ? "u" : \
433 #if !defined PRIxPTR || PRI_MACROS_BROKEN
436 (sizeof (void *) == sizeof (long) ? "lx" : \
437 sizeof (void *) == sizeof (int) ? "x" : \
440 #if !defined PRIXPTR || PRI_MACROS_BROKEN
443 (sizeof (void *) == sizeof (long) ? "lX" : \
444 sizeof (void *) == sizeof (int) ? "X" : \
448 /* @@ end of prolog @@ */
451 /* Rename the non ISO C functions. This is required by the standard
452 because some ISO C functions will require linking with this object
453 file and the name space must not be polluted. */
455 # define close __close
458 # define munmap __munmap
461 /* For those losing systems which don't have `alloca' we have to add
462 some additional code emulating it. */
464 # define freea(p) /* nothing */
466 # define alloca(n) malloc (n)
467 # define freea(p) free (p)
470 /* For systems that distinguish between text and binary I/O.
471 O_BINARY is usually declared in <fcntl.h>. */
472 #if !defined O_BINARY && defined _O_BINARY
473 /* For MSC-compatible compilers. */
474 # define O_BINARY _O_BINARY
475 # define O_TEXT _O_TEXT
478 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
482 /* On reasonable systems, binary I/O is the default. */
488 /* Prototypes for local functions. Needed to ensure compiler checking of
489 function argument counts despite of K&R C function definition syntax. */
490 static const char *get_sysdep_segment_value PARAMS ((const char *name));
493 /* We need a sign, whether a new catalog was loaded, which can be associated
494 with all translations. This is important if the translations are
495 cached by one of GCC's features. */
496 int _nl_msg_cat_cntr;
499 /* Expand a system dependent string segment. Return NULL if unsupported. */
501 get_sysdep_segment_value (name)
504 /* Test for an ISO C 99 section 7.8.1 format string directive.
506 P R I { d | i | o | u | x | X }
507 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
508 /* We don't use a table of 14 times 6 'const char *' strings here, because
509 data relocations cost startup time. */
510 if (name[0] == 'P' && name[1] == 'R' && name[2] == 'I')
512 if (name[3] == 'd' || name[3] == 'i' || name[3] == 'o' || name[3] == 'u'
513 || name[3] == 'x' || name[3] == 'X')
515 if (name[4] == '8' && name[5] == '\0')
531 if (name[4] == '1' && name[5] == '6' && name[6] == '\0')
547 if (name[4] == '3' && name[5] == '2' && name[6] == '\0')
563 if (name[4] == '6' && name[5] == '4' && name[6] == '\0')
579 if (name[4] == 'L' && name[5] == 'E' && name[6] == 'A'
580 && name[7] == 'S' && name[8] == 'T')
582 if (name[9] == '8' && name[10] == '\0')
598 if (name[9] == '1' && name[10] == '6' && name[11] == '\0')
614 if (name[9] == '3' && name[10] == '2' && name[11] == '\0')
630 if (name[9] == '6' && name[10] == '4' && name[11] == '\0')
647 if (name[4] == 'F' && name[5] == 'A' && name[6] == 'S'
650 if (name[8] == '8' && name[9] == '\0')
666 if (name[8] == '1' && name[9] == '6' && name[10] == '\0')
682 if (name[8] == '3' && name[9] == '2' && name[10] == '\0')
698 if (name[8] == '6' && name[9] == '4' && name[10] == '\0')
715 if (name[4] == 'M' && name[5] == 'A' && name[6] == 'X'
732 if (name[4] == 'P' && name[5] == 'T' && name[6] == 'R'
751 /* Other system dependent strings are not valid. */
755 /* Initialize the codeset dependent parts of an opened message catalog.
756 Return the header entry. */
759 _nl_init_domain_conv (domain_file, domain, domainbinding)
760 struct loaded_l10nfile *domain_file;
761 struct loaded_domain *domain;
762 struct binding *domainbinding;
764 /* Find out about the character set the file is encoded with.
765 This can be found (in textual form) in the entry "". If this
766 entry does not exist or if this does not contain the `charset='
767 information, we will assume the charset matches the one the
768 current locale and we don't have to perform any conversion. */
772 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
773 domain->codeset_cntr =
774 (domainbinding != NULL ? domainbinding->codeset_cntr : 0);
776 domain->conv = (__gconv_t) -1;
779 domain->conv = (iconv_t) -1;
782 domain->conv_tab = NULL;
784 /* Get the header entry. */
785 nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen);
787 if (nullentry != NULL)
789 #if defined _LIBC || HAVE_ICONV
790 const char *charsetstr;
792 charsetstr = strstr (nullentry, "charset=");
793 if (charsetstr != NULL)
797 const char *outcharset;
799 charsetstr += strlen ("charset=");
800 len = strcspn (charsetstr, " \t\n");
802 charset = (char *) alloca (len + 1);
803 # if defined _LIBC || HAVE_MEMPCPY
804 *((char *) mempcpy (charset, charsetstr, len)) = '\0';
806 memcpy (charset, charsetstr, len);
810 /* The output charset should normally be determined by the
811 locale. But sometimes the locale is not used or not correctly
812 set up, so we provide a possibility for the user to override
813 this. Moreover, the value specified through
814 bind_textdomain_codeset overrides both. */
815 if (domainbinding != NULL && domainbinding->codeset != NULL)
816 outcharset = domainbinding->codeset;
819 outcharset = getenv ("OUTPUT_CHARSET");
820 if (outcharset == NULL || outcharset[0] == '\0')
823 outcharset = (*_nl_current[LC_CTYPE])->values[_NL_ITEM_INDEX (CODESET)].string;
826 extern const char *locale_charset PARAMS ((void));
827 outcharset = locale_charset ();
834 /* We always want to use transliteration. */
835 outcharset = norm_add_slashes (outcharset, "TRANSLIT");
836 charset = norm_add_slashes (charset, NULL);
837 if (__gconv_open (outcharset, charset, &domain->conv,
840 domain->conv = (__gconv_t) -1;
843 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
844 we want to use transliteration. */
845 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
846 || _LIBICONV_VERSION >= 0x0105
847 if (strchr (outcharset, '/') == NULL)
851 len = strlen (outcharset);
852 tmp = (char *) alloca (len + 10 + 1);
853 memcpy (tmp, outcharset, len);
854 memcpy (tmp + len, "//TRANSLIT", 10 + 1);
857 domain->conv = iconv_open (outcharset, charset);
863 domain->conv = iconv_open (outcharset, charset);
869 #endif /* _LIBC || HAVE_ICONV */
875 /* Frees the codeset dependent parts of an opened message catalog. */
878 _nl_free_domain_conv (domain)
879 struct loaded_domain *domain;
881 if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1)
882 free (domain->conv_tab);
885 if (domain->conv != (__gconv_t) -1)
886 __gconv_close (domain->conv);
889 if (domain->conv != (iconv_t) -1)
890 iconv_close (domain->conv);
895 /* Load the message catalogs specified by FILENAME. If it is no valid
896 message catalog do nothing. */
899 _nl_load_domain (domain_file, domainbinding)
900 struct loaded_l10nfile *domain_file;
901 struct binding *domainbinding;
910 struct mo_file_header *data = (struct mo_file_header *) -1;
912 struct loaded_domain *domain;
914 const char *nullentry;
916 domain_file->decided = 1;
917 domain_file->data = NULL;
919 /* Note that it would be useless to store domainbinding in domain_file
920 because domainbinding might be == NULL now but != NULL later (after
921 a call to bind_textdomain_codeset). */
923 /* If the record does not represent a valid locale the FILENAME
924 might be NULL. This can happen when according to the given
925 specification the locale file name is different for XPG and CEN
927 if (domain_file->filename == NULL)
930 /* Try to open the addressed file. */
931 fd = open (domain_file->filename, O_RDONLY | O_BINARY);
935 /* We must know about the size of the file. */
938 __builtin_expect (fstat64 (fd, &st) != 0, 0)
940 __builtin_expect (fstat (fd, &st) != 0, 0)
942 || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
943 || __builtin_expect (size < sizeof (struct mo_file_header), 0))
945 /* Something went wrong. */
951 /* Now we are ready to load the file. If mmap() is available we try
952 this first. If not available or it failed we try to load it. */
953 data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
956 if (__builtin_expect (data != (struct mo_file_header *) -1, 1))
958 /* mmap() call was successful. */
964 /* If the data is not yet available (i.e. mmap'ed) we try to load
966 if (data == (struct mo_file_header *) -1)
971 data = (struct mo_file_header *) malloc (size);
976 read_ptr = (char *) data;
979 long int nb = (long int) read (fd, read_ptr, to_read);
983 if (nb == -1 && errno == EINTR)
997 /* Using the magic number we can test whether it really is a message
999 if (__builtin_expect (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED,
1002 /* The magic number is wrong: not a message catalog file. */
1005 munmap ((caddr_t) data, size);
1012 domain = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
1015 domain_file->data = domain;
1017 domain->data = (char *) data;
1018 domain->use_mmap = use_mmap;
1019 domain->mmap_size = size;
1020 domain->must_swap = data->magic != _MAGIC;
1021 domain->malloced = NULL;
1023 /* Fill in the information about the available tables. */
1024 revision = W (domain->must_swap, data->revision);
1025 /* We support only the major revision 0. */
1026 switch (revision >> 16)
1029 domain->nstrings = W (domain->must_swap, data->nstrings);
1030 domain->orig_tab = (const struct string_desc *)
1031 ((char *) data + W (domain->must_swap, data->orig_tab_offset));
1032 domain->trans_tab = (const struct string_desc *)
1033 ((char *) data + W (domain->must_swap, data->trans_tab_offset));
1034 domain->hash_size = W (domain->must_swap, data->hash_tab_size);
1036 (domain->hash_size > 2
1037 ? (const nls_uint32 *)
1038 ((char *) data + W (domain->must_swap, data->hash_tab_offset))
1040 domain->must_swap_hash_tab = domain->must_swap;
1042 /* Now dispatch on the minor revision. */
1043 switch (revision & 0xffff)
1046 domain->n_sysdep_strings = 0;
1047 domain->orig_sysdep_tab = NULL;
1048 domain->trans_sysdep_tab = NULL;
1053 nls_uint32 n_sysdep_strings;
1055 if (domain->hash_tab == NULL)
1056 /* This is invalid. These minor revisions need a hash table. */
1060 W (domain->must_swap, data->n_sysdep_strings);
1061 if (n_sysdep_strings > 0)
1063 nls_uint32 n_sysdep_segments;
1064 const struct sysdep_segment *sysdep_segments;
1065 const char **sysdep_segment_values;
1066 const nls_uint32 *orig_sysdep_tab;
1067 const nls_uint32 *trans_sysdep_tab;
1070 struct sysdep_string_desc *inmem_orig_sysdep_tab;
1071 struct sysdep_string_desc *inmem_trans_sysdep_tab;
1072 nls_uint32 *inmem_hash_tab;
1075 /* Get the values of the system dependent segments. */
1077 W (domain->must_swap, data->n_sysdep_segments);
1078 sysdep_segments = (const struct sysdep_segment *)
1080 + W (domain->must_swap, data->sysdep_segments_offset));
1081 sysdep_segment_values =
1082 alloca (n_sysdep_segments * sizeof (const char *));
1083 for (i = 0; i < n_sysdep_segments; i++)
1087 + W (domain->must_swap, sysdep_segments[i].offset);
1088 nls_uint32 namelen =
1089 W (domain->must_swap, sysdep_segments[i].length);
1091 if (!(namelen > 0 && name[namelen - 1] == '\0'))
1093 freea (sysdep_segment_values);
1097 sysdep_segment_values[i] = get_sysdep_segment_value (name);
1100 orig_sysdep_tab = (const nls_uint32 *)
1102 + W (domain->must_swap, data->orig_sysdep_tab_offset));
1103 trans_sysdep_tab = (const nls_uint32 *)
1105 + W (domain->must_swap, data->trans_sysdep_tab_offset));
1107 /* Compute the amount of additional memory needed for the
1108 system dependent strings and the augmented hash table. */
1109 memneed = 2 * n_sysdep_strings
1110 * sizeof (struct sysdep_string_desc)
1111 + domain->hash_size * sizeof (nls_uint32);
1112 for (i = 0; i < 2 * n_sysdep_strings; i++)
1114 const struct sysdep_string *sysdep_string =
1115 (const struct sysdep_string *)
1117 + W (domain->must_swap,
1118 i < n_sysdep_strings
1119 ? orig_sysdep_tab[i]
1120 : trans_sysdep_tab[i - n_sysdep_strings]));
1122 const struct segment_pair *p = sysdep_string->segments;
1124 if (W (domain->must_swap, p->sysdepref) != SEGMENTS_END)
1125 for (p = sysdep_string->segments;; p++)
1127 nls_uint32 sysdepref;
1129 need += W (domain->must_swap, p->segsize);
1131 sysdepref = W (domain->must_swap, p->sysdepref);
1132 if (sysdepref == SEGMENTS_END)
1135 if (sysdepref >= n_sysdep_segments)
1138 freea (sysdep_segment_values);
1142 need += strlen (sysdep_segment_values[sysdepref]);
1148 /* Allocate additional memory. */
1149 mem = (char *) malloc (memneed);
1153 domain->malloced = mem;
1154 inmem_orig_sysdep_tab = (struct sysdep_string_desc *) mem;
1155 mem += n_sysdep_strings * sizeof (struct sysdep_string_desc);
1156 inmem_trans_sysdep_tab = (struct sysdep_string_desc *) mem;
1157 mem += n_sysdep_strings * sizeof (struct sysdep_string_desc);
1158 inmem_hash_tab = (nls_uint32 *) mem;
1159 mem += domain->hash_size * sizeof (nls_uint32);
1161 /* Compute the system dependent strings. */
1162 for (i = 0; i < 2 * n_sysdep_strings; i++)
1164 const struct sysdep_string *sysdep_string =
1165 (const struct sysdep_string *)
1167 + W (domain->must_swap,
1168 i < n_sysdep_strings
1169 ? orig_sysdep_tab[i]
1170 : trans_sysdep_tab[i - n_sysdep_strings]));
1171 const char *static_segments =
1173 + W (domain->must_swap, sysdep_string->offset);
1174 const struct segment_pair *p = sysdep_string->segments;
1176 /* Concatenate the segments, and fill
1177 inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and
1178 inmem_trans_sysdep_tab[i-n_sysdep_strings] (for
1179 i >= n_sysdep_strings). */
1181 if (W (domain->must_swap, p->sysdepref) == SEGMENTS_END)
1183 /* Only one static segment. */
1184 inmem_orig_sysdep_tab[i].length =
1185 W (domain->must_swap, p->segsize);
1186 inmem_orig_sysdep_tab[i].pointer = static_segments;
1190 inmem_orig_sysdep_tab[i].pointer = mem;
1192 for (p = sysdep_string->segments;; p++)
1194 nls_uint32 segsize =
1195 W (domain->must_swap, p->segsize);
1196 nls_uint32 sysdepref =
1197 W (domain->must_swap, p->sysdepref);
1202 memcpy (mem, static_segments, segsize);
1204 static_segments += segsize;
1207 if (sysdepref == SEGMENTS_END)
1210 n = strlen (sysdep_segment_values[sysdepref]);
1211 memcpy (mem, sysdep_segment_values[sysdepref], n);
1215 inmem_orig_sysdep_tab[i].length =
1216 mem - inmem_orig_sysdep_tab[i].pointer;
1220 /* Compute the augmented hash table. */
1221 for (i = 0; i < domain->hash_size; i++)
1223 W (domain->must_swap_hash_tab, domain->hash_tab[i]);
1224 for (i = 0; i < n_sysdep_strings; i++)
1226 const char *msgid = inmem_orig_sysdep_tab[i].pointer;
1227 nls_uint32 hash_val = hash_string (msgid);
1228 nls_uint32 idx = hash_val % domain->hash_size;
1229 nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2));
1233 if (inmem_hash_tab[idx] == 0)
1235 /* Hash table entry is empty. Use it. */
1236 inmem_hash_tab[idx] = 1 + domain->nstrings + i;
1240 if (idx >= domain->hash_size - incr)
1241 idx -= domain->hash_size - incr;
1247 freea (sysdep_segment_values);
1249 domain->n_sysdep_strings = n_sysdep_strings;
1250 domain->orig_sysdep_tab = inmem_orig_sysdep_tab;
1251 domain->trans_sysdep_tab = inmem_trans_sysdep_tab;
1253 domain->hash_tab = inmem_hash_tab;
1254 domain->must_swap_hash_tab = 0;
1258 domain->n_sysdep_strings = 0;
1259 domain->orig_sysdep_tab = NULL;
1260 domain->trans_sysdep_tab = NULL;
1267 /* This is an invalid revision. */
1269 /* This is an invalid .mo file. */
1270 if (domain->malloced)
1271 free (domain->malloced);
1274 munmap ((caddr_t) data, size);
1279 domain_file->data = NULL;
1283 /* Now initialize the character set converter from the character set
1284 the file is encoded with (found in the header entry) to the domain's
1285 specified character set or the locale's character set. */
1286 nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding);
1288 /* Also look for a plural specification. */
1289 EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals);
1296 _nl_unload_domain (domain)
1297 struct loaded_domain *domain;
1299 if (domain->plural != &__gettext_germanic_plural)
1300 __gettext_free_exp (domain->plural);
1302 _nl_free_domain_conv (domain);
1304 if (domain->malloced)
1305 free (domain->malloced);
1307 # ifdef _POSIX_MAPPED_FILES
1308 if (domain->use_mmap)
1309 munmap ((caddr_t) domain->data, domain->mmap_size);
1311 # endif /* _POSIX_MAPPED_FILES */
1312 free ((void *) domain->data);