1 /* Load needed message catalogs.
2 Copyright (C) 1995-1999, 2000-2003 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>
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 /* Prototypes for local functions. Needed to ensure compiler checking of
495 function argument counts despite of K&R C function definition syntax. */
496 static const char *get_sysdep_segment_value
PARAMS ((const char *name
));
499 /* We need a sign, whether a new catalog was loaded, which can be associated
500 with all translations. This is important if the translations are
501 cached by one of GCC's features. */
502 int _nl_msg_cat_cntr
;
505 /* Expand a system dependent string segment. Return NULL if unsupported. */
507 get_sysdep_segment_value (name
)
510 /* Test for an ISO C 99 section 7.8.1 format string directive.
512 P R I { d | i | o | u | x | X }
513 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
514 /* We don't use a table of 14 times 6 'const char *' strings here, because
515 data relocations cost startup time. */
516 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
518 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
519 || name
[3] == 'x' || name
[3] == 'X')
521 if (name
[4] == '8' && name
[5] == '\0')
537 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
553 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
569 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
585 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
586 && name
[7] == 'S' && name
[8] == 'T')
588 if (name
[9] == '8' && name
[10] == '\0')
604 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
620 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
636 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
653 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
656 if (name
[8] == '8' && name
[9] == '\0')
672 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
688 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
704 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
721 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
738 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
757 /* Other system dependent strings are not valid. */
761 /* Initialize the codeset dependent parts of an opened message catalog.
762 Return the header entry. */
765 _nl_init_domain_conv (domain_file
, domain
, domainbinding
)
766 struct loaded_l10nfile
*domain_file
;
767 struct loaded_domain
*domain
;
768 struct binding
*domainbinding
;
770 /* Find out about the character set the file is encoded with.
771 This can be found (in textual form) in the entry "". If this
772 entry does not exist or if this does not contain the `charset='
773 information, we will assume the charset matches the one the
774 current locale and we don't have to perform any conversion. */
778 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
779 domain
->codeset_cntr
=
780 (domainbinding
!= NULL
? domainbinding
->codeset_cntr
: 0);
782 domain
->conv
= (__gconv_t
) -1;
785 domain
->conv
= (iconv_t
) -1;
788 domain
->conv_tab
= NULL
;
790 /* Get the header entry. */
791 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", &nullentrylen
);
793 if (nullentry
!= NULL
)
795 #if defined _LIBC || HAVE_ICONV
796 const char *charsetstr
;
798 charsetstr
= strstr (nullentry
, "charset=");
799 if (charsetstr
!= NULL
)
803 const char *outcharset
;
805 charsetstr
+= strlen ("charset=");
806 len
= strcspn (charsetstr
, " \t\n");
808 charset
= (char *) alloca (len
+ 1);
809 # if defined _LIBC || HAVE_MEMPCPY
810 *((char *) mempcpy (charset
, charsetstr
, len
)) = '\0';
812 memcpy (charset
, charsetstr
, len
);
816 /* The output charset should normally be determined by the
817 locale. But sometimes the locale is not used or not correctly
818 set up, so we provide a possibility for the user to override
819 this. Moreover, the value specified through
820 bind_textdomain_codeset overrides both. */
821 if (domainbinding
!= NULL
&& domainbinding
->codeset
!= NULL
)
822 outcharset
= domainbinding
->codeset
;
825 outcharset
= getenv ("OUTPUT_CHARSET");
826 if (outcharset
== NULL
|| outcharset
[0] == '\0')
829 outcharset
= _NL_CURRENT (LC_CTYPE
, CODESET
);
832 extern const char *locale_charset
PARAMS ((void));
833 outcharset
= locale_charset ();
840 /* We always want to use transliteration. */
841 outcharset
= norm_add_slashes (outcharset
, "TRANSLIT");
842 charset
= norm_add_slashes (charset
, NULL
);
843 if (__gconv_open (outcharset
, charset
, &domain
->conv
,
846 domain
->conv
= (__gconv_t
) -1;
849 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
850 we want to use transliteration. */
851 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
852 || _LIBICONV_VERSION >= 0x0105
853 if (strchr (outcharset
, '/') == NULL
)
857 len
= strlen (outcharset
);
858 tmp
= (char *) alloca (len
+ 10 + 1);
859 memcpy (tmp
, outcharset
, len
);
860 memcpy (tmp
+ len
, "//TRANSLIT", 10 + 1);
863 domain
->conv
= iconv_open (outcharset
, charset
);
869 domain
->conv
= iconv_open (outcharset
, charset
);
875 #endif /* _LIBC || HAVE_ICONV */
881 /* Frees the codeset dependent parts of an opened message catalog. */
884 _nl_free_domain_conv (domain
)
885 struct loaded_domain
*domain
;
887 if (domain
->conv_tab
!= NULL
&& domain
->conv_tab
!= (char **) -1)
888 free (domain
->conv_tab
);
891 if (domain
->conv
!= (__gconv_t
) -1)
892 __gconv_close (domain
->conv
);
895 if (domain
->conv
!= (iconv_t
) -1)
896 iconv_close (domain
->conv
);
901 /* Load the message catalogs specified by FILENAME. If it is no valid
902 message catalog do nothing. */
905 _nl_load_domain (domain_file
, domainbinding
)
906 struct loaded_l10nfile
*domain_file
;
907 struct binding
*domainbinding
;
916 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
918 struct loaded_domain
*domain
;
920 const char *nullentry
;
922 domain_file
->decided
= 1;
923 domain_file
->data
= NULL
;
925 /* Note that it would be useless to store domainbinding in domain_file
926 because domainbinding might be == NULL now but != NULL later (after
927 a call to bind_textdomain_codeset). */
929 /* If the record does not represent a valid locale the FILENAME
930 might be NULL. This can happen when according to the given
931 specification the locale file name is different for XPG and CEN
933 if (domain_file
->filename
== NULL
)
936 /* Try to open the addressed file. */
937 fd
= open (domain_file
->filename
, O_RDONLY
| O_BINARY
);
941 /* We must know about the size of the file. */
944 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
946 __builtin_expect (fstat (fd
, &st
) != 0, 0)
948 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
949 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
951 /* Something went wrong. */
957 /* Now we are ready to load the file. If mmap() is available we try
958 this first. If not available or it failed we try to load it. */
959 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
962 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
964 /* mmap() call was successful. */
970 /* If the data is not yet available (i.e. mmap'ed) we try to load
972 if (data
== (struct mo_file_header
*) -1)
977 data
= (struct mo_file_header
*) malloc (size
);
982 read_ptr
= (char *) data
;
985 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
989 if (nb
== -1 && errno
== EINTR
)
1003 /* Using the magic number we can test whether it really is a message
1005 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
1008 /* The magic number is wrong: not a message catalog file. */
1011 munmap ((caddr_t
) data
, size
);
1018 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
1021 domain_file
->data
= domain
;
1023 domain
->data
= (char *) data
;
1024 domain
->use_mmap
= use_mmap
;
1025 domain
->mmap_size
= size
;
1026 domain
->must_swap
= data
->magic
!= _MAGIC
;
1027 domain
->malloced
= NULL
;
1029 /* Fill in the information about the available tables. */
1030 revision
= W (domain
->must_swap
, data
->revision
);
1031 /* We support only the major revision 0. */
1032 switch (revision
>> 16)
1035 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
1036 domain
->orig_tab
= (const struct string_desc
*)
1037 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
1038 domain
->trans_tab
= (const struct string_desc
*)
1039 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
1040 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
1042 (domain
->hash_size
> 2
1043 ? (const nls_uint32
*)
1044 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
1046 domain
->must_swap_hash_tab
= domain
->must_swap
;
1048 /* Now dispatch on the minor revision. */
1049 switch (revision
& 0xffff)
1052 domain
->n_sysdep_strings
= 0;
1053 domain
->orig_sysdep_tab
= NULL
;
1054 domain
->trans_sysdep_tab
= NULL
;
1059 nls_uint32 n_sysdep_strings
;
1061 if (domain
->hash_tab
== NULL
)
1062 /* This is invalid. These minor revisions need a hash table. */
1066 W (domain
->must_swap
, data
->n_sysdep_strings
);
1067 if (n_sysdep_strings
> 0)
1069 nls_uint32 n_sysdep_segments
;
1070 const struct sysdep_segment
*sysdep_segments
;
1071 const char **sysdep_segment_values
;
1072 const nls_uint32
*orig_sysdep_tab
;
1073 const nls_uint32
*trans_sysdep_tab
;
1076 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
1077 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
1078 nls_uint32
*inmem_hash_tab
;
1081 /* Get the values of the system dependent segments. */
1083 W (domain
->must_swap
, data
->n_sysdep_segments
);
1084 sysdep_segments
= (const struct sysdep_segment
*)
1086 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
1087 sysdep_segment_values
=
1088 alloca (n_sysdep_segments
* sizeof (const char *));
1089 for (i
= 0; i
< n_sysdep_segments
; i
++)
1093 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
1094 nls_uint32 namelen
=
1095 W (domain
->must_swap
, sysdep_segments
[i
].length
);
1097 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
1099 freea (sysdep_segment_values
);
1103 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
1106 orig_sysdep_tab
= (const nls_uint32
*)
1108 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1109 trans_sysdep_tab
= (const nls_uint32
*)
1111 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1113 /* Compute the amount of additional memory needed for the
1114 system dependent strings and the augmented hash table. */
1115 memneed
= 2 * n_sysdep_strings
1116 * sizeof (struct sysdep_string_desc
)
1117 + domain
->hash_size
* sizeof (nls_uint32
);
1118 for (i
= 0; i
< 2 * n_sysdep_strings
; i
++)
1120 const struct sysdep_string
*sysdep_string
=
1121 (const struct sysdep_string
*)
1123 + W (domain
->must_swap
,
1124 i
< n_sysdep_strings
1125 ? orig_sysdep_tab
[i
]
1126 : trans_sysdep_tab
[i
- n_sysdep_strings
]));
1128 const struct segment_pair
*p
= sysdep_string
->segments
;
1130 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1131 for (p
= sysdep_string
->segments
;; p
++)
1133 nls_uint32 sysdepref
;
1135 need
+= W (domain
->must_swap
, p
->segsize
);
1137 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1138 if (sysdepref
== SEGMENTS_END
)
1141 if (sysdepref
>= n_sysdep_segments
)
1144 freea (sysdep_segment_values
);
1148 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1154 /* Allocate additional memory. */
1155 mem
= (char *) malloc (memneed
);
1159 domain
->malloced
= mem
;
1160 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1161 mem
+= n_sysdep_strings
* sizeof (struct sysdep_string_desc
);
1162 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1163 mem
+= n_sysdep_strings
* sizeof (struct sysdep_string_desc
);
1164 inmem_hash_tab
= (nls_uint32
*) mem
;
1165 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1167 /* Compute the system dependent strings. */
1168 for (i
= 0; i
< 2 * n_sysdep_strings
; i
++)
1170 const struct sysdep_string
*sysdep_string
=
1171 (const struct sysdep_string
*)
1173 + W (domain
->must_swap
,
1174 i
< n_sysdep_strings
1175 ? orig_sysdep_tab
[i
]
1176 : trans_sysdep_tab
[i
- n_sysdep_strings
]));
1177 const char *static_segments
=
1179 + W (domain
->must_swap
, sysdep_string
->offset
);
1180 const struct segment_pair
*p
= sysdep_string
->segments
;
1182 /* Concatenate the segments, and fill
1183 inmem_orig_sysdep_tab[i] (for i < n_sysdep_strings) and
1184 inmem_trans_sysdep_tab[i-n_sysdep_strings] (for
1185 i >= n_sysdep_strings). */
1187 if (W (domain
->must_swap
, p
->sysdepref
) == SEGMENTS_END
)
1189 /* Only one static segment. */
1190 inmem_orig_sysdep_tab
[i
].length
=
1191 W (domain
->must_swap
, p
->segsize
);
1192 inmem_orig_sysdep_tab
[i
].pointer
= static_segments
;
1196 inmem_orig_sysdep_tab
[i
].pointer
= mem
;
1198 for (p
= sysdep_string
->segments
;; p
++)
1200 nls_uint32 segsize
=
1201 W (domain
->must_swap
, p
->segsize
);
1202 nls_uint32 sysdepref
=
1203 W (domain
->must_swap
, p
->sysdepref
);
1208 memcpy (mem
, static_segments
, segsize
);
1210 static_segments
+= segsize
;
1213 if (sysdepref
== SEGMENTS_END
)
1216 n
= strlen (sysdep_segment_values
[sysdepref
]);
1217 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1221 inmem_orig_sysdep_tab
[i
].length
=
1222 mem
- inmem_orig_sysdep_tab
[i
].pointer
;
1226 /* Compute the augmented hash table. */
1227 for (i
= 0; i
< domain
->hash_size
; i
++)
1229 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1230 for (i
= 0; i
< n_sysdep_strings
; i
++)
1232 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1233 nls_uint32 hash_val
= hash_string (msgid
);
1234 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1235 nls_uint32 incr
= 1 + (hash_val
% (domain
->hash_size
- 2));
1239 if (inmem_hash_tab
[idx
] == 0)
1241 /* Hash table entry is empty. Use it. */
1242 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1246 if (idx
>= domain
->hash_size
- incr
)
1247 idx
-= domain
->hash_size
- incr
;
1253 freea (sysdep_segment_values
);
1255 domain
->n_sysdep_strings
= n_sysdep_strings
;
1256 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1257 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1259 domain
->hash_tab
= inmem_hash_tab
;
1260 domain
->must_swap_hash_tab
= 0;
1264 domain
->n_sysdep_strings
= 0;
1265 domain
->orig_sysdep_tab
= NULL
;
1266 domain
->trans_sysdep_tab
= NULL
;
1273 /* This is an invalid revision. */
1275 /* This is an invalid .mo file. */
1276 if (domain
->malloced
)
1277 free (domain
->malloced
);
1280 munmap ((caddr_t
) data
, size
);
1285 domain_file
->data
= NULL
;
1289 /* Now initialize the character set converter from the character set
1290 the file is encoded with (found in the header entry) to the domain's
1291 specified character set or the locale's character set. */
1292 nullentry
= _nl_init_domain_conv (domain_file
, domain
, domainbinding
);
1294 /* Also look for a plural specification. */
1295 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1302 _nl_unload_domain (domain
)
1303 struct loaded_domain
*domain
;
1305 if (domain
->plural
!= &__gettext_germanic_plural
)
1306 __gettext_free_exp (domain
->plural
);
1308 _nl_free_domain_conv (domain
);
1310 if (domain
->malloced
)
1311 free (domain
->malloced
);
1313 # ifdef _POSIX_MAPPED_FILES
1314 if (domain
->use_mmap
)
1315 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1317 # endif /* _POSIX_MAPPED_FILES */
1318 free ((void *) domain
->data
);