1 /* Load needed message catalogs.
2 Copyright (C) 1995-2002, 2003 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
PARAMS ((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 if (strchr (outcharset
, '/') == NULL
)
836 len
= strlen (outcharset
);
837 tmp
= (char *) alloca (len
+ 10 + 1);
838 memcpy (tmp
, outcharset
, len
);
839 memcpy (tmp
+ len
, "//TRANSLIT", 10 + 1);
842 domain
->conv
= iconv_open (outcharset
, charset
);
848 domain
->conv
= iconv_open (outcharset
, charset
);
854 #endif /* _LIBC || HAVE_ICONV */
860 /* Frees the codeset dependent parts of an opened message catalog. */
863 _nl_free_domain_conv (domain
)
864 struct loaded_domain
*domain
;
866 if (domain
->conv_tab
!= NULL
&& domain
->conv_tab
!= (char **) -1)
867 free (domain
->conv_tab
);
870 if (domain
->conv
!= (__gconv_t
) -1)
871 __gconv_close (domain
->conv
);
874 if (domain
->conv
!= (iconv_t
) -1)
875 iconv_close (domain
->conv
);
880 /* Load the message catalogs specified by FILENAME. If it is no valid
881 message catalog do nothing. */
884 _nl_load_domain (domain_file
, domainbinding
)
885 struct loaded_l10nfile
*domain_file
;
886 struct binding
*domainbinding
;
895 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
897 struct loaded_domain
*domain
;
899 const char *nullentry
;
901 domain_file
->decided
= 1;
902 domain_file
->data
= NULL
;
904 /* Note that it would be useless to store domainbinding in domain_file
905 because domainbinding might be == NULL now but != NULL later (after
906 a call to bind_textdomain_codeset). */
908 /* If the record does not represent a valid locale the FILENAME
909 might be NULL. This can happen when according to the given
910 specification the locale file name is different for XPG and CEN
912 if (domain_file
->filename
== NULL
)
915 /* Try to open the addressed file. */
916 fd
= open (domain_file
->filename
, O_RDONLY
);
920 /* We must know about the size of the file. */
923 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
925 __builtin_expect (fstat (fd
, &st
) != 0, 0)
927 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
928 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
930 /* Something went wrong. */
936 /* Now we are ready to load the file. If mmap() is available we try
937 this first. If not available or it failed we try to load it. */
938 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
941 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
943 /* mmap() call was successful. */
949 /* If the data is not yet available (i.e. mmap'ed) we try to load
951 if (data
== (struct mo_file_header
*) -1)
956 data
= (struct mo_file_header
*) malloc (size
);
961 read_ptr
= (char *) data
;
964 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
968 if (nb
== -1 && errno
== EINTR
)
982 /* Using the magic number we can test whether it really is a message
984 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
987 /* The magic number is wrong: not a message catalog file. */
990 munmap ((caddr_t
) data
, size
);
997 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
1000 domain_file
->data
= domain
;
1002 domain
->data
= (char *) data
;
1003 domain
->use_mmap
= use_mmap
;
1004 domain
->mmap_size
= size
;
1005 domain
->must_swap
= data
->magic
!= _MAGIC
;
1006 domain
->malloced
= NULL
;
1008 /* Fill in the information about the available tables. */
1009 revision
= W (domain
->must_swap
, data
->revision
);
1010 /* We support only the major revision 0. */
1011 switch (revision
>> 16)
1014 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
1015 domain
->orig_tab
= (const struct string_desc
*)
1016 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
1017 domain
->trans_tab
= (const struct string_desc
*)
1018 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
1019 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
1021 (domain
->hash_size
> 2
1022 ? (const nls_uint32
*)
1023 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
1025 domain
->must_swap_hash_tab
= domain
->must_swap
;
1027 /* Now dispatch on the minor revision. */
1028 switch (revision
& 0xffff)
1031 domain
->n_sysdep_strings
= 0;
1032 domain
->orig_sysdep_tab
= NULL
;
1033 domain
->trans_sysdep_tab
= NULL
;
1038 nls_uint32 n_sysdep_strings
;
1040 if (domain
->hash_tab
== NULL
)
1041 /* This is invalid. These minor revisions need a hash table. */
1045 W (domain
->must_swap
, data
->n_sysdep_strings
);
1046 if (n_sysdep_strings
> 0)
1048 nls_uint32 n_sysdep_segments
;
1049 const struct sysdep_segment
*sysdep_segments
;
1050 const char **sysdep_segment_values
;
1051 const nls_uint32
*orig_sysdep_tab
;
1052 const nls_uint32
*trans_sysdep_tab
;
1055 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
1056 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
1057 nls_uint32
*inmem_hash_tab
;
1060 /* Get the values of the system dependent segments. */
1062 W (domain
->must_swap
, data
->n_sysdep_segments
);
1063 sysdep_segments
= (const struct sysdep_segment
*)
1065 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
1066 sysdep_segment_values
=
1067 alloca (n_sysdep_segments
* sizeof (const char *));
1068 for (i
= 0; i
< n_sysdep_segments
; i
++)
1072 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
1073 nls_uint32 namelen
=
1074 W (domain
->must_swap
, sysdep_segments
[i
].length
);
1076 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
1078 freea (sysdep_segment_values
);
1082 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
1085 orig_sysdep_tab
= (const nls_uint32
*)
1087 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1088 trans_sysdep_tab
= (const nls_uint32
*)
1090 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1092 /* Compute the amount of additional memory needed for the
1093 system dependent strings and the augmented hash table. */
1094 memneed
= 2 * n_sysdep_strings
1095 * sizeof (struct sysdep_string_desc
)
1096 + domain
->hash_size
* sizeof (nls_uint32
);
1097 for (i
= 0; i
< 2 * n_sysdep_strings
; i
++)
1099 const struct sysdep_string
*sysdep_string
=
1100 (const struct sysdep_string
*)
1102 + W (domain
->must_swap
,
1103 i
< n_sysdep_strings
1104 ? orig_sysdep_tab
[i
]
1105 : trans_sysdep_tab
[i
- n_sysdep_strings
]));
1107 const struct segment_pair
*p
= sysdep_string
->segments
;
1109 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1110 for (p
= sysdep_string
->segments
;; p
++)
1112 nls_uint32 sysdepref
;
1114 need
+= W (domain
->must_swap
, p
->segsize
);
1116 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1117 if (sysdepref
== SEGMENTS_END
)
1120 if (sysdepref
>= n_sysdep_segments
)
1123 freea (sysdep_segment_values
);
1127 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1133 /* Allocate additional memory. */
1134 mem
= (char *) malloc (memneed
);
1138 domain
->malloced
= mem
;
1139 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1140 mem
+= n_sysdep_strings
* sizeof (struct sysdep_string_desc
);
1141 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1142 mem
+= n_sysdep_strings
* sizeof (struct sysdep_string_desc
);
1143 inmem_hash_tab
= (nls_uint32
*) mem
;
1144 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1146 /* Compute the system dependent strings. */
1147 for (i
= 0; i
< 2 * n_sysdep_strings
; i
++)
1149 const struct sysdep_string
*sysdep_string
=
1150 (const struct sysdep_string
*)
1152 + W (domain
->must_swap
,
1153 i
< n_sysdep_strings
1154 ? orig_sysdep_tab
[i
]
1155 : trans_sysdep_tab
[i
- n_sysdep_strings
]));
1156 const char *static_segments
=
1158 + W (domain
->must_swap
, sysdep_string
->offset
);
1159 const struct segment_pair
*p
= sysdep_string
->segments
;
1161 /* Concatenate the segments, and fill
1162 inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and
1163 inmem_trans_sysdep_tab[i-n_sysdep_strings] (for
1164 i >= n_sysdep_strings). */
1166 if (W (domain
->must_swap
, p
->sysdepref
) == SEGMENTS_END
)
1168 /* Only one static segment. */
1169 inmem_orig_sysdep_tab
[i
].length
=
1170 W (domain
->must_swap
, p
->segsize
);
1171 inmem_orig_sysdep_tab
[i
].pointer
= static_segments
;
1175 inmem_orig_sysdep_tab
[i
].pointer
= mem
;
1177 for (p
= sysdep_string
->segments
;; p
++)
1179 nls_uint32 segsize
=
1180 W (domain
->must_swap
, p
->segsize
);
1181 nls_uint32 sysdepref
=
1182 W (domain
->must_swap
, p
->sysdepref
);
1187 memcpy (mem
, static_segments
, segsize
);
1189 static_segments
+= segsize
;
1192 if (sysdepref
== SEGMENTS_END
)
1195 n
= strlen (sysdep_segment_values
[sysdepref
]);
1196 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1200 inmem_orig_sysdep_tab
[i
].length
=
1201 mem
- inmem_orig_sysdep_tab
[i
].pointer
;
1205 /* Compute the augmented hash table. */
1206 for (i
= 0; i
< domain
->hash_size
; i
++)
1208 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1209 for (i
= 0; i
< n_sysdep_strings
; i
++)
1211 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1212 nls_uint32 hash_val
= __hash_string (msgid
);
1213 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1214 nls_uint32 incr
= 1 + (hash_val
% (domain
->hash_size
- 2));
1218 if (inmem_hash_tab
[idx
] == 0)
1220 /* Hash table entry is empty. Use it. */
1221 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1225 if (idx
>= domain
->hash_size
- incr
)
1226 idx
-= domain
->hash_size
- incr
;
1232 freea (sysdep_segment_values
);
1234 domain
->n_sysdep_strings
= n_sysdep_strings
;
1235 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1236 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1238 domain
->hash_tab
= inmem_hash_tab
;
1239 domain
->must_swap_hash_tab
= 0;
1243 domain
->n_sysdep_strings
= 0;
1244 domain
->orig_sysdep_tab
= NULL
;
1245 domain
->trans_sysdep_tab
= NULL
;
1252 /* This is an invalid revision. */
1254 /* This is an invalid .mo file. */
1255 if (domain
->malloced
)
1256 free (domain
->malloced
);
1259 munmap ((caddr_t
) data
, size
);
1264 domain_file
->data
= NULL
;
1268 /* Now initialize the character set converter from the character set
1269 the file is encoded with (found in the header entry) to the domain's
1270 specified character set or the locale's character set. */
1271 nullentry
= _nl_init_domain_conv (domain_file
, domain
, domainbinding
);
1273 /* Also look for a plural specification. */
1274 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1281 _nl_unload_domain (domain
)
1282 struct loaded_domain
*domain
;
1284 if (domain
->plural
!= &__gettext_germanic_plural
)
1285 __gettext_free_exp (domain
->plural
);
1287 _nl_free_domain_conv (domain
);
1289 if (domain
->malloced
)
1290 free (domain
->malloced
);
1292 # ifdef _POSIX_MAPPED_FILES
1293 if (domain
->use_mmap
)
1294 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1296 # endif /* _POSIX_MAPPED_FILES */
1297 free ((void *) domain
->data
);