1 /* Load needed message catalogs.
2 Copyright (C) 1995-2004 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"
90 # include <not-cancel.h>
93 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
94 Note that our fallback values need not be literal strings, because we don't
95 use them with preprocessor string concatenation. */
96 #if !defined PRId8 || PRI_MACROS_BROKEN
100 #if !defined PRIi8 || PRI_MACROS_BROKEN
104 #if !defined PRIo8 || PRI_MACROS_BROKEN
108 #if !defined PRIu8 || PRI_MACROS_BROKEN
112 #if !defined PRIx8 || PRI_MACROS_BROKEN
116 #if !defined PRIX8 || PRI_MACROS_BROKEN
120 #if !defined PRId16 || PRI_MACROS_BROKEN
124 #if !defined PRIi16 || PRI_MACROS_BROKEN
128 #if !defined PRIo16 || PRI_MACROS_BROKEN
132 #if !defined PRIu16 || PRI_MACROS_BROKEN
136 #if !defined PRIx16 || PRI_MACROS_BROKEN
140 #if !defined PRIX16 || PRI_MACROS_BROKEN
144 #if !defined PRId32 || PRI_MACROS_BROKEN
148 #if !defined PRIi32 || PRI_MACROS_BROKEN
152 #if !defined PRIo32 || PRI_MACROS_BROKEN
156 #if !defined PRIu32 || PRI_MACROS_BROKEN
160 #if !defined PRIx32 || PRI_MACROS_BROKEN
164 #if !defined PRIX32 || PRI_MACROS_BROKEN
168 #if !defined PRId64 || PRI_MACROS_BROKEN
170 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
172 #if !defined PRIi64 || PRI_MACROS_BROKEN
174 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
176 #if !defined PRIo64 || PRI_MACROS_BROKEN
178 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
180 #if !defined PRIu64 || PRI_MACROS_BROKEN
182 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
184 #if !defined PRIx64 || PRI_MACROS_BROKEN
186 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
188 #if !defined PRIX64 || PRI_MACROS_BROKEN
190 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
192 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
194 # define PRIdLEAST8 "d"
196 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
198 # define PRIiLEAST8 "i"
200 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
202 # define PRIoLEAST8 "o"
204 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
206 # define PRIuLEAST8 "u"
208 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
210 # define PRIxLEAST8 "x"
212 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
214 # define PRIXLEAST8 "X"
216 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
218 # define PRIdLEAST16 "d"
220 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
222 # define PRIiLEAST16 "i"
224 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
226 # define PRIoLEAST16 "o"
228 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
230 # define PRIuLEAST16 "u"
232 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
234 # define PRIxLEAST16 "x"
236 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
238 # define PRIXLEAST16 "X"
240 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
242 # define PRIdLEAST32 "d"
244 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
246 # define PRIiLEAST32 "i"
248 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
250 # define PRIoLEAST32 "o"
252 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
254 # define PRIuLEAST32 "u"
256 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
258 # define PRIxLEAST32 "x"
260 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
262 # define PRIXLEAST32 "X"
264 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
266 # define PRIdLEAST64 PRId64
268 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
270 # define PRIiLEAST64 PRIi64
272 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
274 # define PRIoLEAST64 PRIo64
276 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
278 # define PRIuLEAST64 PRIu64
280 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
282 # define PRIxLEAST64 PRIx64
284 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
286 # define PRIXLEAST64 PRIX64
288 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
290 # define PRIdFAST8 "d"
292 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
294 # define PRIiFAST8 "i"
296 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
298 # define PRIoFAST8 "o"
300 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
302 # define PRIuFAST8 "u"
304 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
306 # define PRIxFAST8 "x"
308 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
310 # define PRIXFAST8 "X"
312 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
314 # define PRIdFAST16 "d"
316 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
318 # define PRIiFAST16 "i"
320 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
322 # define PRIoFAST16 "o"
324 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
326 # define PRIuFAST16 "u"
328 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
330 # define PRIxFAST16 "x"
332 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
334 # define PRIXFAST16 "X"
336 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
338 # define PRIdFAST32 "d"
340 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
342 # define PRIiFAST32 "i"
344 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
346 # define PRIoFAST32 "o"
348 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
350 # define PRIuFAST32 "u"
352 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
354 # define PRIxFAST32 "x"
356 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
358 # define PRIXFAST32 "X"
360 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
362 # define PRIdFAST64 PRId64
364 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
366 # define PRIiFAST64 PRIi64
368 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
370 # define PRIoFAST64 PRIo64
372 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
374 # define PRIuFAST64 PRIu64
376 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
378 # define PRIxFAST64 PRIx64
380 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
382 # define PRIXFAST64 PRIX64
384 #if !defined PRIdMAX || PRI_MACROS_BROKEN
386 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
388 #if !defined PRIiMAX || PRI_MACROS_BROKEN
390 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
392 #if !defined PRIoMAX || PRI_MACROS_BROKEN
394 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
396 #if !defined PRIuMAX || PRI_MACROS_BROKEN
398 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
400 #if !defined PRIxMAX || PRI_MACROS_BROKEN
402 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
404 #if !defined PRIXMAX || PRI_MACROS_BROKEN
406 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
408 #if !defined PRIdPTR || PRI_MACROS_BROKEN
411 (sizeof (void *) == sizeof (long) ? "ld" : \
412 sizeof (void *) == sizeof (int) ? "d" : \
415 #if !defined PRIiPTR || PRI_MACROS_BROKEN
418 (sizeof (void *) == sizeof (long) ? "li" : \
419 sizeof (void *) == sizeof (int) ? "i" : \
422 #if !defined PRIoPTR || PRI_MACROS_BROKEN
425 (sizeof (void *) == sizeof (long) ? "lo" : \
426 sizeof (void *) == sizeof (int) ? "o" : \
429 #if !defined PRIuPTR || PRI_MACROS_BROKEN
432 (sizeof (void *) == sizeof (long) ? "lu" : \
433 sizeof (void *) == sizeof (int) ? "u" : \
436 #if !defined PRIxPTR || PRI_MACROS_BROKEN
439 (sizeof (void *) == sizeof (long) ? "lx" : \
440 sizeof (void *) == sizeof (int) ? "x" : \
443 #if !defined PRIXPTR || PRI_MACROS_BROKEN
446 (sizeof (void *) == sizeof (long) ? "lX" : \
447 sizeof (void *) == sizeof (int) ? "X" : \
451 /* @@ end of prolog @@ */
454 /* Rename the non ISO C functions. This is required by the standard
455 because some ISO C functions will require linking with this object
456 file and the name space must not be polluted. */
457 # define open(name, flags) open_not_cancel_2 (name, flags)
458 # define close(fd) close_not_cancel_no_status (fd)
459 # define read(fd, buf, n) read_not_cancel (fd, buf, n)
460 # define mmap(addr, len, prot, flags, fd, offset) \
461 __mmap (addr, len, prot, flags, fd, offset)
462 # define munmap(addr, len) __munmap (addr, len)
465 /* For those losing systems which don't have `alloca' we have to add
466 some additional code emulating it. */
468 # define freea(p) /* nothing */
470 # define alloca(n) malloc (n)
471 # define freea(p) free (p)
475 /* Prototypes for local functions. Needed to ensure compiler checking of
476 function argument counts despite of K&R C function definition syntax. */
477 static const char *get_sysdep_segment_value
PARAMS ((const char *name
));
480 /* We need a sign, whether a new catalog was loaded, which can be associated
481 with all translations. This is important if the translations are
482 cached by one of GCC's features. */
483 int _nl_msg_cat_cntr
;
486 /* Expand a system dependent string segment. Return NULL if unsupported. */
488 get_sysdep_segment_value (name
)
491 /* Test for an ISO C 99 section 7.8.1 format string directive.
493 P R I { d | i | o | u | x | X }
494 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
495 /* We don't use a table of 14 times 6 'const char *' strings here, because
496 data relocations cost startup time. */
497 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
499 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
500 || name
[3] == 'x' || name
[3] == 'X')
502 if (name
[4] == '8' && name
[5] == '\0')
518 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
534 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
550 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
566 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
567 && name
[7] == 'S' && name
[8] == 'T')
569 if (name
[9] == '8' && name
[10] == '\0')
585 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
601 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
617 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
634 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
637 if (name
[8] == '8' && name
[9] == '\0')
653 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
669 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
685 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
702 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
719 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
738 /* Test for a glibc specific printf() format directive flag. */
739 if (name
[0] == 'I' && name
[1] == '\0')
741 #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
742 /* The 'I' flag, in numeric format directives, replaces ASCII digits
743 with the 'outdigits' defined in the LC_CTYPE locale facet. This is
744 used for Farsi (Persian) and maybe Arabic. */
750 /* Other system dependent strings are not valid. */
754 /* Initialize the codeset dependent parts of an opened message catalog.
755 Return the header entry. */
758 _nl_init_domain_conv (domain_file
, domain
, domainbinding
)
759 struct loaded_l10nfile
*domain_file
;
760 struct loaded_domain
*domain
;
761 struct binding
*domainbinding
;
763 /* Find out about the character set the file is encoded with.
764 This can be found (in textual form) in the entry "". If this
765 entry does not exist or if this does not contain the `charset='
766 information, we will assume the charset matches the one the
767 current locale and we don't have to perform any conversion. */
771 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
772 domain
->codeset_cntr
=
773 (domainbinding
!= NULL
? domainbinding
->codeset_cntr
: 0);
775 domain
->conv
= (__gconv_t
) -1;
778 domain
->conv
= (iconv_t
) -1;
781 domain
->conv_tab
= NULL
;
783 /* Get the header entry. */
784 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", &nullentrylen
);
786 if (nullentry
!= NULL
)
788 #if defined _LIBC || HAVE_ICONV
789 const char *charsetstr
;
791 charsetstr
= strstr (nullentry
, "charset=");
792 if (charsetstr
!= NULL
)
796 const char *outcharset
;
798 charsetstr
+= strlen ("charset=");
799 len
= strcspn (charsetstr
, " \t\n");
801 charset
= (char *) alloca (len
+ 1);
802 # if defined _LIBC || HAVE_MEMPCPY
803 *((char *) mempcpy (charset
, charsetstr
, len
)) = '\0';
805 memcpy (charset
, charsetstr
, len
);
809 /* The output charset should normally be determined by the
810 locale. But sometimes the locale is not used or not correctly
811 set up, so we provide a possibility for the user to override
812 this. Moreover, the value specified through
813 bind_textdomain_codeset overrides both. */
814 if (domainbinding
!= NULL
&& domainbinding
->codeset
!= NULL
)
815 outcharset
= domainbinding
->codeset
;
818 outcharset
= getenv ("OUTPUT_CHARSET");
819 if (outcharset
== NULL
|| outcharset
[0] == '\0')
822 outcharset
= _NL_CURRENT (LC_CTYPE
, CODESET
);
825 extern const char *locale_charset
PARAMS ((void));
826 outcharset
= locale_charset ();
833 /* We always want to use transliteration. */
834 outcharset
= norm_add_slashes (outcharset
, "TRANSLIT");
835 charset
= norm_add_slashes (charset
, "");
836 if (__gconv_open (outcharset
, charset
, &domain
->conv
,
839 domain
->conv
= (__gconv_t
) -1;
842 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
843 we want to use transliteration. */
844 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
845 || _LIBICONV_VERSION >= 0x0105
846 if (strchr (outcharset
, '/') == NULL
)
850 len
= strlen (outcharset
);
851 tmp
= (char *) alloca (len
+ 10 + 1);
852 memcpy (tmp
, outcharset
, len
);
853 memcpy (tmp
+ len
, "//TRANSLIT", 10 + 1);
856 domain
->conv
= iconv_open (outcharset
, charset
);
862 domain
->conv
= iconv_open (outcharset
, charset
);
868 #endif /* _LIBC || HAVE_ICONV */
874 /* Frees the codeset dependent parts of an opened message catalog. */
877 _nl_free_domain_conv (domain
)
878 struct loaded_domain
*domain
;
880 if (domain
->conv_tab
!= NULL
&& domain
->conv_tab
!= (char **) -1)
881 free (domain
->conv_tab
);
884 if (domain
->conv
!= (__gconv_t
) -1)
885 __gconv_close (domain
->conv
);
888 if (domain
->conv
!= (iconv_t
) -1)
889 iconv_close (domain
->conv
);
894 /* Load the message catalogs specified by FILENAME. If it is no valid
895 message catalog do nothing. */
898 _nl_load_domain (domain_file
, domainbinding
)
899 struct loaded_l10nfile
*domain_file
;
900 struct binding
*domainbinding
;
909 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
911 struct loaded_domain
*domain
;
913 const char *nullentry
;
915 domain_file
->decided
= 1;
916 domain_file
->data
= NULL
;
918 /* Note that it would be useless to store domainbinding in domain_file
919 because domainbinding might be == NULL now but != NULL later (after
920 a call to bind_textdomain_codeset). */
922 /* If the record does not represent a valid locale the FILENAME
923 might be NULL. This can happen when according to the given
924 specification the locale file name is different for XPG and CEN
926 if (domain_file
->filename
== NULL
)
929 /* Try to open the addressed file. */
930 fd
= open (domain_file
->filename
, O_RDONLY
);
934 /* We must know about the size of the file. */
937 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
939 __builtin_expect (fstat (fd
, &st
) != 0, 0)
941 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
942 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
944 /* Something went wrong. */
950 /* Now we are ready to load the file. If mmap() is available we try
951 this first. If not available or it failed we try to load it. */
952 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
955 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
957 /* mmap() call was successful. */
963 /* If the data is not yet available (i.e. mmap'ed) we try to load
965 if (data
== (struct mo_file_header
*) -1)
970 data
= (struct mo_file_header
*) malloc (size
);
975 read_ptr
= (char *) data
;
978 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
982 if (nb
== -1 && errno
== EINTR
)
996 /* Using the magic number we can test whether it really is a message
998 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
1001 /* The magic number is wrong: not a message catalog file. */
1004 munmap ((caddr_t
) data
, size
);
1011 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
1014 domain_file
->data
= domain
;
1016 domain
->data
= (char *) data
;
1017 domain
->use_mmap
= use_mmap
;
1018 domain
->mmap_size
= size
;
1019 domain
->must_swap
= data
->magic
!= _MAGIC
;
1020 domain
->malloced
= NULL
;
1022 /* Fill in the information about the available tables. */
1023 revision
= W (domain
->must_swap
, data
->revision
);
1024 /* We support only the major revisions 0 and 1. */
1025 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
;
1068 nls_uint32 n_inmem_sysdep_strings
;
1071 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
1072 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
1073 nls_uint32
*inmem_hash_tab
;
1076 /* Get the values of the system dependent segments. */
1078 W (domain
->must_swap
, data
->n_sysdep_segments
);
1079 sysdep_segments
= (const struct sysdep_segment
*)
1081 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
1082 sysdep_segment_values
=
1083 alloca (n_sysdep_segments
* sizeof (const char *));
1084 for (i
= 0; i
< n_sysdep_segments
; i
++)
1088 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
1089 nls_uint32 namelen
=
1090 W (domain
->must_swap
, sysdep_segments
[i
].length
);
1092 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
1094 freea (sysdep_segment_values
);
1098 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
1101 orig_sysdep_tab
= (const nls_uint32
*)
1103 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1104 trans_sysdep_tab
= (const nls_uint32
*)
1106 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1108 /* Compute the amount of additional memory needed for the
1109 system dependent strings and the augmented hash table.
1110 At the same time, also drop string pairs which refer to
1111 an undefined system dependent segment. */
1112 n_inmem_sysdep_strings
= 0;
1113 memneed
= domain
->hash_size
* sizeof (nls_uint32
);
1114 for (i
= 0; i
< n_sysdep_strings
; i
++)
1119 for (j
= 0; j
< 2; j
++)
1121 const struct sysdep_string
*sysdep_string
=
1122 (const struct sysdep_string
*)
1124 + W (domain
->must_swap
,
1126 ? orig_sysdep_tab
[i
]
1127 : trans_sysdep_tab
[i
]));
1129 const struct segment_pair
*p
= sysdep_string
->segments
;
1131 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1132 for (p
= sysdep_string
->segments
;; p
++)
1134 nls_uint32 sysdepref
;
1136 need
+= W (domain
->must_swap
, p
->segsize
);
1138 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1139 if (sysdepref
== SEGMENTS_END
)
1142 if (sysdepref
>= n_sysdep_segments
)
1145 freea (sysdep_segment_values
);
1149 if (sysdep_segment_values
[sysdepref
] == NULL
)
1151 /* This particular string pair is invalid. */
1156 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1166 n_inmem_sysdep_strings
++;
1167 memneed
+= needs
[0] + needs
[1];
1170 memneed
+= 2 * n_inmem_sysdep_strings
1171 * sizeof (struct sysdep_string_desc
);
1173 if (n_inmem_sysdep_strings
> 0)
1177 /* Allocate additional memory. */
1178 mem
= (char *) malloc (memneed
);
1182 domain
->malloced
= mem
;
1183 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1184 mem
+= n_inmem_sysdep_strings
1185 * sizeof (struct sysdep_string_desc
);
1186 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1187 mem
+= n_inmem_sysdep_strings
1188 * sizeof (struct sysdep_string_desc
);
1189 inmem_hash_tab
= (nls_uint32
*) mem
;
1190 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1192 /* Compute the system dependent strings. */
1194 for (i
= 0; i
< n_sysdep_strings
; i
++)
1198 for (j
= 0; j
< 2; j
++)
1200 const struct sysdep_string
*sysdep_string
=
1201 (const struct sysdep_string
*)
1203 + W (domain
->must_swap
,
1205 ? orig_sysdep_tab
[i
]
1206 : trans_sysdep_tab
[i
]));
1207 const struct segment_pair
*p
=
1208 sysdep_string
->segments
;
1210 if (W (domain
->must_swap
, p
->sysdepref
)
1212 for (p
= sysdep_string
->segments
;; p
++)
1214 nls_uint32 sysdepref
;
1217 W (domain
->must_swap
, p
->sysdepref
);
1218 if (sysdepref
== SEGMENTS_END
)
1221 if (sysdep_segment_values
[sysdepref
] == NULL
)
1223 /* This particular string pair is
1236 for (j
= 0; j
< 2; j
++)
1238 const struct sysdep_string
*sysdep_string
=
1239 (const struct sysdep_string
*)
1241 + W (domain
->must_swap
,
1243 ? orig_sysdep_tab
[i
]
1244 : trans_sysdep_tab
[i
]));
1245 const char *static_segments
=
1247 + W (domain
->must_swap
, sysdep_string
->offset
);
1248 const struct segment_pair
*p
=
1249 sysdep_string
->segments
;
1251 /* Concatenate the segments, and fill
1252 inmem_orig_sysdep_tab[k] (for j == 0) and
1253 inmem_trans_sysdep_tab[k] (for j == 1). */
1255 struct sysdep_string_desc
*inmem_tab_entry
=
1257 ? inmem_orig_sysdep_tab
1258 : inmem_trans_sysdep_tab
)
1261 if (W (domain
->must_swap
, p
->sysdepref
)
1264 /* Only one static segment. */
1265 inmem_tab_entry
->length
=
1266 W (domain
->must_swap
, p
->segsize
);
1267 inmem_tab_entry
->pointer
= static_segments
;
1271 inmem_tab_entry
->pointer
= mem
;
1273 for (p
= sysdep_string
->segments
;; p
++)
1275 nls_uint32 segsize
=
1276 W (domain
->must_swap
, p
->segsize
);
1277 nls_uint32 sysdepref
=
1278 W (domain
->must_swap
, p
->sysdepref
);
1283 memcpy (mem
, static_segments
, segsize
);
1285 static_segments
+= segsize
;
1288 if (sysdepref
== SEGMENTS_END
)
1291 n
= strlen (sysdep_segment_values
[sysdepref
]);
1292 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1296 inmem_tab_entry
->length
=
1297 mem
- inmem_tab_entry
->pointer
;
1304 if (k
!= n_inmem_sysdep_strings
)
1307 /* Compute the augmented hash table. */
1308 for (i
= 0; i
< domain
->hash_size
; i
++)
1310 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1311 for (i
= 0; i
< n_inmem_sysdep_strings
; i
++)
1313 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1314 nls_uint32 hash_val
= __hash_string (msgid
);
1315 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1317 1 + (hash_val
% (domain
->hash_size
- 2));
1321 if (inmem_hash_tab
[idx
] == 0)
1323 /* Hash table entry is empty. Use it. */
1324 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1328 if (idx
>= domain
->hash_size
- incr
)
1329 idx
-= domain
->hash_size
- incr
;
1335 domain
->n_sysdep_strings
= n_inmem_sysdep_strings
;
1336 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1337 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1339 domain
->hash_tab
= inmem_hash_tab
;
1340 domain
->must_swap_hash_tab
= 0;
1344 domain
->n_sysdep_strings
= 0;
1345 domain
->orig_sysdep_tab
= NULL
;
1346 domain
->trans_sysdep_tab
= NULL
;
1349 freea (sysdep_segment_values
);
1353 domain
->n_sysdep_strings
= 0;
1354 domain
->orig_sysdep_tab
= NULL
;
1355 domain
->trans_sysdep_tab
= NULL
;
1362 /* This is an invalid revision. */
1364 /* This is an invalid .mo file. */
1365 if (domain
->malloced
)
1366 free (domain
->malloced
);
1369 munmap ((caddr_t
) data
, size
);
1374 domain_file
->data
= NULL
;
1378 /* Now initialize the character set converter from the character set
1379 the file is encoded with (found in the header entry) to the domain's
1380 specified character set or the locale's character set. */
1381 nullentry
= _nl_init_domain_conv (domain_file
, domain
, domainbinding
);
1383 /* Also look for a plural specification. */
1384 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1390 internal_function __libc_freeres_fn_section
1391 _nl_unload_domain (domain
)
1392 struct loaded_domain
*domain
;
1394 if (domain
->plural
!= &__gettext_germanic_plural
)
1395 __gettext_free_exp (domain
->plural
);
1397 _nl_free_domain_conv (domain
);
1399 if (domain
->malloced
)
1400 free (domain
->malloced
);
1402 # ifdef _POSIX_MAPPED_FILES
1403 if (domain
->use_mmap
)
1404 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1406 # endif /* _POSIX_MAPPED_FILES */
1407 free ((void *) domain
->data
);