1 /* Load needed message catalogs.
2 Copyright (C) 1995-1999, 2000-2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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>
38 # define alloca __builtin_alloca
39 # define HAVE_ALLOCA 1
43 # define alloca _alloca
45 # if defined HAVE_ALLOCA_H || defined _LIBC
62 #if defined HAVE_UNISTD_H || defined _LIBC
67 # include <langinfo.h>
71 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
72 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
73 # include <sys/mman.h>
80 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
83 #if defined HAVE_INTTYPES_H || defined _LIBC
84 # include <inttypes.h>
89 #include "hash-string.h"
90 #include "plural-exp.h"
93 # include "../locale/localeinfo.h"
96 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
97 Note that our fallback values need not be literal strings, because we don't
98 use them with preprocessor string concatenation. */
99 #if !defined PRId8 || PRI_MACROS_BROKEN
103 #if !defined PRIi8 || PRI_MACROS_BROKEN
107 #if !defined PRIo8 || PRI_MACROS_BROKEN
111 #if !defined PRIu8 || PRI_MACROS_BROKEN
115 #if !defined PRIx8 || PRI_MACROS_BROKEN
119 #if !defined PRIX8 || PRI_MACROS_BROKEN
123 #if !defined PRId16 || PRI_MACROS_BROKEN
127 #if !defined PRIi16 || PRI_MACROS_BROKEN
131 #if !defined PRIo16 || PRI_MACROS_BROKEN
135 #if !defined PRIu16 || PRI_MACROS_BROKEN
139 #if !defined PRIx16 || PRI_MACROS_BROKEN
143 #if !defined PRIX16 || PRI_MACROS_BROKEN
147 #if !defined PRId32 || PRI_MACROS_BROKEN
151 #if !defined PRIi32 || PRI_MACROS_BROKEN
155 #if !defined PRIo32 || PRI_MACROS_BROKEN
159 #if !defined PRIu32 || PRI_MACROS_BROKEN
163 #if !defined PRIx32 || PRI_MACROS_BROKEN
167 #if !defined PRIX32 || PRI_MACROS_BROKEN
171 #if !defined PRId64 || PRI_MACROS_BROKEN
173 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
175 #if !defined PRIi64 || PRI_MACROS_BROKEN
177 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
179 #if !defined PRIo64 || PRI_MACROS_BROKEN
181 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
183 #if !defined PRIu64 || PRI_MACROS_BROKEN
185 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
187 #if !defined PRIx64 || PRI_MACROS_BROKEN
189 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
191 #if !defined PRIX64 || PRI_MACROS_BROKEN
193 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
195 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
197 # define PRIdLEAST8 "d"
199 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
201 # define PRIiLEAST8 "i"
203 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
205 # define PRIoLEAST8 "o"
207 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
209 # define PRIuLEAST8 "u"
211 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
213 # define PRIxLEAST8 "x"
215 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
217 # define PRIXLEAST8 "X"
219 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
221 # define PRIdLEAST16 "d"
223 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
225 # define PRIiLEAST16 "i"
227 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
229 # define PRIoLEAST16 "o"
231 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
233 # define PRIuLEAST16 "u"
235 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
237 # define PRIxLEAST16 "x"
239 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
241 # define PRIXLEAST16 "X"
243 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
245 # define PRIdLEAST32 "d"
247 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
249 # define PRIiLEAST32 "i"
251 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
253 # define PRIoLEAST32 "o"
255 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
257 # define PRIuLEAST32 "u"
259 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
261 # define PRIxLEAST32 "x"
263 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
265 # define PRIXLEAST32 "X"
267 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
269 # define PRIdLEAST64 PRId64
271 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
273 # define PRIiLEAST64 PRIi64
275 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
277 # define PRIoLEAST64 PRIo64
279 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
281 # define PRIuLEAST64 PRIu64
283 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
285 # define PRIxLEAST64 PRIx64
287 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
289 # define PRIXLEAST64 PRIX64
291 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
293 # define PRIdFAST8 "d"
295 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
297 # define PRIiFAST8 "i"
299 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
301 # define PRIoFAST8 "o"
303 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
305 # define PRIuFAST8 "u"
307 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
309 # define PRIxFAST8 "x"
311 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
313 # define PRIXFAST8 "X"
315 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
317 # define PRIdFAST16 "d"
319 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
321 # define PRIiFAST16 "i"
323 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
325 # define PRIoFAST16 "o"
327 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
329 # define PRIuFAST16 "u"
331 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
333 # define PRIxFAST16 "x"
335 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
337 # define PRIXFAST16 "X"
339 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
341 # define PRIdFAST32 "d"
343 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
345 # define PRIiFAST32 "i"
347 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
349 # define PRIoFAST32 "o"
351 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
353 # define PRIuFAST32 "u"
355 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
357 # define PRIxFAST32 "x"
359 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
361 # define PRIXFAST32 "X"
363 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
365 # define PRIdFAST64 PRId64
367 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
369 # define PRIiFAST64 PRIi64
371 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
373 # define PRIoFAST64 PRIo64
375 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
377 # define PRIuFAST64 PRIu64
379 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
381 # define PRIxFAST64 PRIx64
383 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
385 # define PRIXFAST64 PRIX64
387 #if !defined PRIdMAX || PRI_MACROS_BROKEN
389 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
391 #if !defined PRIiMAX || PRI_MACROS_BROKEN
393 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
395 #if !defined PRIoMAX || PRI_MACROS_BROKEN
397 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
399 #if !defined PRIuMAX || PRI_MACROS_BROKEN
401 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
403 #if !defined PRIxMAX || PRI_MACROS_BROKEN
405 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
407 #if !defined PRIXMAX || PRI_MACROS_BROKEN
409 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
411 #if !defined PRIdPTR || PRI_MACROS_BROKEN
414 (sizeof (void *) == sizeof (long) ? "ld" : \
415 sizeof (void *) == sizeof (int) ? "d" : \
418 #if !defined PRIiPTR || PRI_MACROS_BROKEN
421 (sizeof (void *) == sizeof (long) ? "li" : \
422 sizeof (void *) == sizeof (int) ? "i" : \
425 #if !defined PRIoPTR || PRI_MACROS_BROKEN
428 (sizeof (void *) == sizeof (long) ? "lo" : \
429 sizeof (void *) == sizeof (int) ? "o" : \
432 #if !defined PRIuPTR || PRI_MACROS_BROKEN
435 (sizeof (void *) == sizeof (long) ? "lu" : \
436 sizeof (void *) == sizeof (int) ? "u" : \
439 #if !defined PRIxPTR || PRI_MACROS_BROKEN
442 (sizeof (void *) == sizeof (long) ? "lx" : \
443 sizeof (void *) == sizeof (int) ? "x" : \
446 #if !defined PRIXPTR || PRI_MACROS_BROKEN
449 (sizeof (void *) == sizeof (long) ? "lX" : \
450 sizeof (void *) == sizeof (int) ? "X" : \
454 /* @@ end of prolog @@ */
457 /* Rename the non ISO C functions. This is required by the standard
458 because some ISO C functions will require linking with this object
459 file and the name space must not be polluted. */
461 # define close __close
464 # define munmap __munmap
467 /* For those losing systems which don't have `alloca' we have to add
468 some additional code emulating it. */
470 # define freea(p) /* nothing */
472 # define alloca(n) malloc (n)
473 # define freea(p) free (p)
476 /* For systems that distinguish between text and binary I/O.
477 O_BINARY is usually declared in <fcntl.h>. */
478 #if !defined O_BINARY && defined _O_BINARY
479 /* For MSC-compatible compilers. */
480 # define O_BINARY _O_BINARY
481 # define O_TEXT _O_TEXT
484 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
488 /* On reasonable systems, binary I/O is the default. */
494 /* We need a sign, whether a new catalog was loaded, which can be associated
495 with all translations. This is important if the translations are
496 cached by one of GCC's features. */
497 int _nl_msg_cat_cntr
;
500 /* Expand a system dependent string segment. Return NULL if unsupported. */
502 get_sysdep_segment_value (const char *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 /* Test for a glibc specific printf() format directive flag. */
752 if (name
[0] == 'I' && name
[1] == '\0')
754 #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
755 /* The 'I' flag, in numeric format directives, replaces ASCII digits
756 with the 'outdigits' defined in the LC_CTYPE locale facet. This is
757 used for Farsi (Persian) and maybe Arabic. */
763 /* Other system dependent strings are not valid. */
767 /* Initialize the codeset dependent parts of an opened message catalog.
768 Return the header entry. */
771 _nl_init_domain_conv (struct loaded_l10nfile
*domain_file
,
772 struct loaded_domain
*domain
,
773 struct binding
*domainbinding
)
775 /* Find out about the character set the file is encoded with.
776 This can be found (in textual form) in the entry "". If this
777 entry does not exist or if this does not contain the `charset='
778 information, we will assume the charset matches the one the
779 current locale and we don't have to perform any conversion. */
783 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
784 domain
->codeset_cntr
=
785 (domainbinding
!= NULL
? domainbinding
->codeset_cntr
: 0);
787 domain
->conv
= (__gconv_t
) -1;
790 domain
->conv
= (iconv_t
) -1;
793 domain
->conv_tab
= NULL
;
795 /* Get the header entry. */
796 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", &nullentrylen
);
798 if (nullentry
!= NULL
)
800 #if defined _LIBC || HAVE_ICONV
801 const char *charsetstr
;
803 charsetstr
= strstr (nullentry
, "charset=");
804 if (charsetstr
!= NULL
)
808 const char *outcharset
;
810 charsetstr
+= strlen ("charset=");
811 len
= strcspn (charsetstr
, " \t\n");
813 charset
= (char *) alloca (len
+ 1);
814 # if defined _LIBC || HAVE_MEMPCPY
815 *((char *) mempcpy (charset
, charsetstr
, len
)) = '\0';
817 memcpy (charset
, charsetstr
, len
);
821 /* The output charset should normally be determined by the
822 locale. But sometimes the locale is not used or not correctly
823 set up, so we provide a possibility for the user to override
824 this. Moreover, the value specified through
825 bind_textdomain_codeset overrides both. */
826 if (domainbinding
!= NULL
&& domainbinding
->codeset
!= NULL
)
827 outcharset
= domainbinding
->codeset
;
830 outcharset
= getenv ("OUTPUT_CHARSET");
831 if (outcharset
== NULL
|| outcharset
[0] == '\0')
834 outcharset
= _NL_CURRENT (LC_CTYPE
, CODESET
);
837 extern const char *locale_charset (void);
838 outcharset
= locale_charset ();
845 /* We always want to use transliteration. */
846 outcharset
= norm_add_slashes (outcharset
, "TRANSLIT");
847 charset
= norm_add_slashes (charset
, NULL
);
848 if (__gconv_open (outcharset
, charset
, &domain
->conv
,
851 domain
->conv
= (__gconv_t
) -1;
854 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
855 we want to use transliteration. */
856 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
857 || _LIBICONV_VERSION >= 0x0105
858 if (strchr (outcharset
, '/') == NULL
)
862 len
= strlen (outcharset
);
863 tmp
= (char *) alloca (len
+ 10 + 1);
864 memcpy (tmp
, outcharset
, len
);
865 memcpy (tmp
+ len
, "//TRANSLIT", 10 + 1);
868 domain
->conv
= iconv_open (outcharset
, charset
);
874 domain
->conv
= iconv_open (outcharset
, charset
);
880 #endif /* _LIBC || HAVE_ICONV */
886 /* Frees the codeset dependent parts of an opened message catalog. */
889 _nl_free_domain_conv (struct loaded_domain
*domain
)
891 if (domain
->conv_tab
!= NULL
&& domain
->conv_tab
!= (char **) -1)
892 free (domain
->conv_tab
);
895 if (domain
->conv
!= (__gconv_t
) -1)
896 __gconv_close (domain
->conv
);
899 if (domain
->conv
!= (iconv_t
) -1)
900 iconv_close (domain
->conv
);
905 /* Load the message catalogs specified by FILENAME. If it is no valid
906 message catalog do nothing. */
909 _nl_load_domain (struct loaded_l10nfile
*domain_file
,
910 struct binding
*domainbinding
)
919 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
921 struct loaded_domain
*domain
;
923 const char *nullentry
;
925 domain_file
->decided
= 1;
926 domain_file
->data
= NULL
;
928 /* Note that it would be useless to store domainbinding in domain_file
929 because domainbinding might be == NULL now but != NULL later (after
930 a call to bind_textdomain_codeset). */
932 /* If the record does not represent a valid locale the FILENAME
933 might be NULL. This can happen when according to the given
934 specification the locale file name is different for XPG and CEN
936 if (domain_file
->filename
== NULL
)
939 /* Try to open the addressed file. */
940 fd
= open (domain_file
->filename
, O_RDONLY
| O_BINARY
);
944 /* We must know about the size of the file. */
947 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
949 __builtin_expect (fstat (fd
, &st
) != 0, 0)
951 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
952 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
954 /* Something went wrong. */
960 /* Now we are ready to load the file. If mmap() is available we try
961 this first. If not available or it failed we try to load it. */
962 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
965 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
967 /* mmap() call was successful. */
973 /* If the data is not yet available (i.e. mmap'ed) we try to load
975 if (data
== (struct mo_file_header
*) -1)
980 data
= (struct mo_file_header
*) malloc (size
);
985 read_ptr
= (char *) data
;
988 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
992 if (nb
== -1 && errno
== EINTR
)
1001 while (to_read
> 0);
1006 /* Using the magic number we can test whether it really is a message
1008 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
1011 /* The magic number is wrong: not a message catalog file. */
1014 munmap ((caddr_t
) data
, size
);
1021 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
1024 domain_file
->data
= domain
;
1026 domain
->data
= (char *) data
;
1027 domain
->use_mmap
= use_mmap
;
1028 domain
->mmap_size
= size
;
1029 domain
->must_swap
= data
->magic
!= _MAGIC
;
1030 domain
->malloced
= NULL
;
1032 /* Fill in the information about the available tables. */
1033 revision
= W (domain
->must_swap
, data
->revision
);
1034 /* We support only the major revisions 0 and 1. */
1035 switch (revision
>> 16)
1039 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
1040 domain
->orig_tab
= (const struct string_desc
*)
1041 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
1042 domain
->trans_tab
= (const struct string_desc
*)
1043 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
1044 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
1046 (domain
->hash_size
> 2
1047 ? (const nls_uint32
*)
1048 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
1050 domain
->must_swap_hash_tab
= domain
->must_swap
;
1052 /* Now dispatch on the minor revision. */
1053 switch (revision
& 0xffff)
1056 domain
->n_sysdep_strings
= 0;
1057 domain
->orig_sysdep_tab
= NULL
;
1058 domain
->trans_sysdep_tab
= NULL
;
1063 nls_uint32 n_sysdep_strings
;
1065 if (domain
->hash_tab
== NULL
)
1066 /* This is invalid. These minor revisions need a hash table. */
1070 W (domain
->must_swap
, data
->n_sysdep_strings
);
1071 if (n_sysdep_strings
> 0)
1073 nls_uint32 n_sysdep_segments
;
1074 const struct sysdep_segment
*sysdep_segments
;
1075 const char **sysdep_segment_values
;
1076 const nls_uint32
*orig_sysdep_tab
;
1077 const nls_uint32
*trans_sysdep_tab
;
1078 nls_uint32 n_inmem_sysdep_strings
;
1081 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
1082 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
1083 nls_uint32
*inmem_hash_tab
;
1086 /* Get the values of the system dependent segments. */
1088 W (domain
->must_swap
, data
->n_sysdep_segments
);
1089 sysdep_segments
= (const struct sysdep_segment
*)
1091 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
1092 sysdep_segment_values
=
1093 alloca (n_sysdep_segments
* sizeof (const char *));
1094 for (i
= 0; i
< n_sysdep_segments
; i
++)
1098 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
1099 nls_uint32 namelen
=
1100 W (domain
->must_swap
, sysdep_segments
[i
].length
);
1102 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
1104 freea (sysdep_segment_values
);
1108 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
1111 orig_sysdep_tab
= (const nls_uint32
*)
1113 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1114 trans_sysdep_tab
= (const nls_uint32
*)
1116 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1118 /* Compute the amount of additional memory needed for the
1119 system dependent strings and the augmented hash table.
1120 At the same time, also drop string pairs which refer to
1121 an undefined system dependent segment. */
1122 n_inmem_sysdep_strings
= 0;
1123 memneed
= domain
->hash_size
* sizeof (nls_uint32
);
1124 for (i
= 0; i
< n_sysdep_strings
; i
++)
1129 for (j
= 0; j
< 2; j
++)
1131 const struct sysdep_string
*sysdep_string
=
1132 (const struct sysdep_string
*)
1134 + W (domain
->must_swap
,
1136 ? orig_sysdep_tab
[i
]
1137 : trans_sysdep_tab
[i
]));
1139 const struct segment_pair
*p
= sysdep_string
->segments
;
1141 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1142 for (p
= sysdep_string
->segments
;; p
++)
1144 nls_uint32 sysdepref
;
1146 need
+= W (domain
->must_swap
, p
->segsize
);
1148 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1149 if (sysdepref
== SEGMENTS_END
)
1152 if (sysdepref
>= n_sysdep_segments
)
1155 freea (sysdep_segment_values
);
1159 if (sysdep_segment_values
[sysdepref
] == NULL
)
1161 /* This particular string pair is invalid. */
1166 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1176 n_inmem_sysdep_strings
++;
1177 memneed
+= needs
[0] + needs
[1];
1180 memneed
+= 2 * n_inmem_sysdep_strings
1181 * sizeof (struct sysdep_string_desc
);
1183 if (n_inmem_sysdep_strings
> 0)
1187 /* Allocate additional memory. */
1188 mem
= (char *) malloc (memneed
);
1192 domain
->malloced
= mem
;
1193 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1194 mem
+= n_inmem_sysdep_strings
1195 * sizeof (struct sysdep_string_desc
);
1196 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1197 mem
+= n_inmem_sysdep_strings
1198 * sizeof (struct sysdep_string_desc
);
1199 inmem_hash_tab
= (nls_uint32
*) mem
;
1200 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1202 /* Compute the system dependent strings. */
1204 for (i
= 0; i
< n_sysdep_strings
; i
++)
1208 for (j
= 0; j
< 2; j
++)
1210 const struct sysdep_string
*sysdep_string
=
1211 (const struct sysdep_string
*)
1213 + W (domain
->must_swap
,
1215 ? orig_sysdep_tab
[i
]
1216 : trans_sysdep_tab
[i
]));
1217 const struct segment_pair
*p
=
1218 sysdep_string
->segments
;
1220 if (W (domain
->must_swap
, p
->sysdepref
)
1222 for (p
= sysdep_string
->segments
;; p
++)
1224 nls_uint32 sysdepref
;
1227 W (domain
->must_swap
, p
->sysdepref
);
1228 if (sysdepref
== SEGMENTS_END
)
1231 if (sysdep_segment_values
[sysdepref
] == NULL
)
1233 /* This particular string pair is
1246 for (j
= 0; j
< 2; j
++)
1248 const struct sysdep_string
*sysdep_string
=
1249 (const struct sysdep_string
*)
1251 + W (domain
->must_swap
,
1253 ? orig_sysdep_tab
[i
]
1254 : trans_sysdep_tab
[i
]));
1255 const char *static_segments
=
1257 + W (domain
->must_swap
, sysdep_string
->offset
);
1258 const struct segment_pair
*p
=
1259 sysdep_string
->segments
;
1261 /* Concatenate the segments, and fill
1262 inmem_orig_sysdep_tab[k] (for j == 0) and
1263 inmem_trans_sysdep_tab[k] (for j == 1). */
1265 struct sysdep_string_desc
*inmem_tab_entry
=
1267 ? inmem_orig_sysdep_tab
1268 : inmem_trans_sysdep_tab
)
1271 if (W (domain
->must_swap
, p
->sysdepref
)
1274 /* Only one static segment. */
1275 inmem_tab_entry
->length
=
1276 W (domain
->must_swap
, p
->segsize
);
1277 inmem_tab_entry
->pointer
= static_segments
;
1281 inmem_tab_entry
->pointer
= mem
;
1283 for (p
= sysdep_string
->segments
;; p
++)
1285 nls_uint32 segsize
=
1286 W (domain
->must_swap
, p
->segsize
);
1287 nls_uint32 sysdepref
=
1288 W (domain
->must_swap
, p
->sysdepref
);
1293 memcpy (mem
, static_segments
, segsize
);
1295 static_segments
+= segsize
;
1298 if (sysdepref
== SEGMENTS_END
)
1301 n
= strlen (sysdep_segment_values
[sysdepref
]);
1302 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1306 inmem_tab_entry
->length
=
1307 mem
- inmem_tab_entry
->pointer
;
1314 if (k
!= n_inmem_sysdep_strings
)
1317 /* Compute the augmented hash table. */
1318 for (i
= 0; i
< domain
->hash_size
; i
++)
1320 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1321 for (i
= 0; i
< n_inmem_sysdep_strings
; i
++)
1323 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1324 nls_uint32 hash_val
= hash_string (msgid
);
1325 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1327 1 + (hash_val
% (domain
->hash_size
- 2));
1331 if (inmem_hash_tab
[idx
] == 0)
1333 /* Hash table entry is empty. Use it. */
1334 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1338 if (idx
>= domain
->hash_size
- incr
)
1339 idx
-= domain
->hash_size
- incr
;
1345 domain
->n_sysdep_strings
= n_inmem_sysdep_strings
;
1346 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1347 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1349 domain
->hash_tab
= inmem_hash_tab
;
1350 domain
->must_swap_hash_tab
= 0;
1354 domain
->n_sysdep_strings
= 0;
1355 domain
->orig_sysdep_tab
= NULL
;
1356 domain
->trans_sysdep_tab
= NULL
;
1359 freea (sysdep_segment_values
);
1363 domain
->n_sysdep_strings
= 0;
1364 domain
->orig_sysdep_tab
= NULL
;
1365 domain
->trans_sysdep_tab
= NULL
;
1372 /* This is an invalid revision. */
1374 /* This is an invalid .mo file. */
1375 if (domain
->malloced
)
1376 free (domain
->malloced
);
1379 munmap ((caddr_t
) data
, size
);
1384 domain_file
->data
= NULL
;
1388 /* Now initialize the character set converter from the character set
1389 the file is encoded with (found in the header entry) to the domain's
1390 specified character set or the locale's character set. */
1391 nullentry
= _nl_init_domain_conv (domain_file
, domain
, domainbinding
);
1393 /* Also look for a plural specification. */
1394 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1401 _nl_unload_domain (struct loaded_domain
*domain
)
1403 if (domain
->plural
!= &__gettext_germanic_plural
)
1404 __gettext_free_exp (domain
->plural
);
1406 _nl_free_domain_conv (domain
);
1408 if (domain
->malloced
)
1409 free (domain
->malloced
);
1411 # ifdef _POSIX_MAPPED_FILES
1412 if (domain
->use_mmap
)
1413 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1415 # endif /* _POSIX_MAPPED_FILES */
1416 free ((void *) domain
->data
);