3 /* Load needed message catalogs.
4 Copyright (C) 1995-1999, 2000-2004 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published
8 by the Free Software Foundation; either version 2, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 /* Tell glibc's <string.h> to provide a prototype for mempcpy().
22 This must come before <config.h> because <config.h> may include
23 <features.h>, and once <features.h> has been included, it's too late. */
25 # define _GNU_SOURCE 1
35 #include <sys/types.h>
40 # define alloca __builtin_alloca
41 # define HAVE_ALLOCA 1
45 # define alloca _alloca
47 # if defined HAVE_ALLOCA_H || defined _LIBC
64 #if defined HAVE_UNISTD_H || defined _LIBC
69 # include <langinfo.h>
73 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
74 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
75 # include <sys/mman.h>
82 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
85 #if defined HAVE_INTTYPES_H || defined _LIBC
86 # include <inttypes.h>
91 #include "hash-string.h"
92 #include "plural-exp.h"
95 # include "../locale/localeinfo.h"
98 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
99 Note that our fallback values need not be literal strings, because we don't
100 use them with preprocessor string concatenation. */
101 #if !defined PRId8 || PRI_MACROS_BROKEN
105 #if !defined PRIi8 || PRI_MACROS_BROKEN
109 #if !defined PRIo8 || PRI_MACROS_BROKEN
113 #if !defined PRIu8 || PRI_MACROS_BROKEN
117 #if !defined PRIx8 || PRI_MACROS_BROKEN
121 #if !defined PRIX8 || PRI_MACROS_BROKEN
125 #if !defined PRId16 || PRI_MACROS_BROKEN
129 #if !defined PRIi16 || PRI_MACROS_BROKEN
133 #if !defined PRIo16 || PRI_MACROS_BROKEN
137 #if !defined PRIu16 || PRI_MACROS_BROKEN
141 #if !defined PRIx16 || PRI_MACROS_BROKEN
145 #if !defined PRIX16 || PRI_MACROS_BROKEN
149 #if !defined PRId32 || PRI_MACROS_BROKEN
153 #if !defined PRIi32 || PRI_MACROS_BROKEN
157 #if !defined PRIo32 || PRI_MACROS_BROKEN
161 #if !defined PRIu32 || PRI_MACROS_BROKEN
165 #if !defined PRIx32 || PRI_MACROS_BROKEN
169 #if !defined PRIX32 || PRI_MACROS_BROKEN
173 #if !defined PRId64 || PRI_MACROS_BROKEN
175 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
177 #if !defined PRIi64 || PRI_MACROS_BROKEN
179 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
181 #if !defined PRIo64 || PRI_MACROS_BROKEN
183 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
185 #if !defined PRIu64 || PRI_MACROS_BROKEN
187 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
189 #if !defined PRIx64 || PRI_MACROS_BROKEN
191 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
193 #if !defined PRIX64 || PRI_MACROS_BROKEN
195 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
197 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
199 # define PRIdLEAST8 "d"
201 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
203 # define PRIiLEAST8 "i"
205 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
207 # define PRIoLEAST8 "o"
209 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
211 # define PRIuLEAST8 "u"
213 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
215 # define PRIxLEAST8 "x"
217 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
219 # define PRIXLEAST8 "X"
221 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
223 # define PRIdLEAST16 "d"
225 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
227 # define PRIiLEAST16 "i"
229 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
231 # define PRIoLEAST16 "o"
233 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
235 # define PRIuLEAST16 "u"
237 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
239 # define PRIxLEAST16 "x"
241 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
243 # define PRIXLEAST16 "X"
245 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
247 # define PRIdLEAST32 "d"
249 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
251 # define PRIiLEAST32 "i"
253 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
255 # define PRIoLEAST32 "o"
257 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
259 # define PRIuLEAST32 "u"
261 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
263 # define PRIxLEAST32 "x"
265 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
267 # define PRIXLEAST32 "X"
269 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
271 # define PRIdLEAST64 PRId64
273 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
275 # define PRIiLEAST64 PRIi64
277 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
279 # define PRIoLEAST64 PRIo64
281 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
283 # define PRIuLEAST64 PRIu64
285 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
287 # define PRIxLEAST64 PRIx64
289 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
291 # define PRIXLEAST64 PRIX64
293 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
295 # define PRIdFAST8 "d"
297 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
299 # define PRIiFAST8 "i"
301 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
303 # define PRIoFAST8 "o"
305 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
307 # define PRIuFAST8 "u"
309 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
311 # define PRIxFAST8 "x"
313 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
315 # define PRIXFAST8 "X"
317 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
319 # define PRIdFAST16 "d"
321 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
323 # define PRIiFAST16 "i"
325 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
327 # define PRIoFAST16 "o"
329 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
331 # define PRIuFAST16 "u"
333 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
335 # define PRIxFAST16 "x"
337 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
339 # define PRIXFAST16 "X"
341 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
343 # define PRIdFAST32 "d"
345 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
347 # define PRIiFAST32 "i"
349 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
351 # define PRIoFAST32 "o"
353 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
355 # define PRIuFAST32 "u"
357 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
359 # define PRIxFAST32 "x"
361 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
363 # define PRIXFAST32 "X"
365 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
367 # define PRIdFAST64 PRId64
369 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
371 # define PRIiFAST64 PRIi64
373 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
375 # define PRIoFAST64 PRIo64
377 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
379 # define PRIuFAST64 PRIu64
381 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
383 # define PRIxFAST64 PRIx64
385 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
387 # define PRIXFAST64 PRIX64
389 #if !defined PRIdMAX || PRI_MACROS_BROKEN
391 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
393 #if !defined PRIiMAX || PRI_MACROS_BROKEN
395 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
397 #if !defined PRIoMAX || PRI_MACROS_BROKEN
399 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
401 #if !defined PRIuMAX || PRI_MACROS_BROKEN
403 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
405 #if !defined PRIxMAX || PRI_MACROS_BROKEN
407 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
409 #if !defined PRIXMAX || PRI_MACROS_BROKEN
411 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
413 #if !defined PRIdPTR || PRI_MACROS_BROKEN
416 (sizeof (void *) == sizeof (long) ? "ld" : \
417 sizeof (void *) == sizeof (int) ? "d" : \
420 #if !defined PRIiPTR || PRI_MACROS_BROKEN
423 (sizeof (void *) == sizeof (long) ? "li" : \
424 sizeof (void *) == sizeof (int) ? "i" : \
427 #if !defined PRIoPTR || PRI_MACROS_BROKEN
430 (sizeof (void *) == sizeof (long) ? "lo" : \
431 sizeof (void *) == sizeof (int) ? "o" : \
434 #if !defined PRIuPTR || PRI_MACROS_BROKEN
437 (sizeof (void *) == sizeof (long) ? "lu" : \
438 sizeof (void *) == sizeof (int) ? "u" : \
441 #if !defined PRIxPTR || PRI_MACROS_BROKEN
444 (sizeof (void *) == sizeof (long) ? "lx" : \
445 sizeof (void *) == sizeof (int) ? "x" : \
448 #if !defined PRIXPTR || PRI_MACROS_BROKEN
451 (sizeof (void *) == sizeof (long) ? "lX" : \
452 sizeof (void *) == sizeof (int) ? "X" : \
456 /* @@ end of prolog @@ */
459 /* Rename the non ISO C functions. This is required by the standard
460 because some ISO C functions will require linking with this object
461 file and the name space must not be polluted. */
463 # define close __close
466 # define munmap __munmap
469 /* For those losing systems which don't have `alloca' we have to add
470 some additional code emulating it. */
472 # define freea(p) /* nothing */
474 # define alloca(n) malloc (n)
475 # define freea(p) free (p)
478 /* For systems that distinguish between text and binary I/O.
479 O_BINARY is usually declared in <fcntl.h>. */
480 #if !defined O_BINARY && defined _O_BINARY
481 /* For MSC-compatible compilers. */
482 # define O_BINARY _O_BINARY
483 # define O_TEXT _O_TEXT
486 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
490 /* On reasonable systems, binary I/O is the default. */
496 /* We need a sign, whether a new catalog was loaded, which can be associated
497 with all translations. This is important if the translations are
498 cached by one of GCC's features. */
499 int _nl_msg_cat_cntr
;
502 /* Expand a system dependent string segment. Return NULL if unsupported. */
504 get_sysdep_segment_value (const char *name
)
506 /* Test for an ISO C 99 section 7.8.1 format string directive.
508 P R I { d | i | o | u | x | X }
509 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
510 /* We don't use a table of 14 times 6 'const char *' strings here, because
511 data relocations cost startup time. */
512 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
514 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
515 || name
[3] == 'x' || name
[3] == 'X')
517 if (name
[4] == '8' && name
[5] == '\0')
533 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
549 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
565 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
581 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
582 && name
[7] == 'S' && name
[8] == 'T')
584 if (name
[9] == '8' && name
[10] == '\0')
600 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
616 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
632 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
649 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
652 if (name
[8] == '8' && name
[9] == '\0')
668 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
684 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
700 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
717 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
734 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
753 /* Test for a glibc specific printf() format directive flag. */
754 if (name
[0] == 'I' && name
[1] == '\0')
756 #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
757 /* The 'I' flag, in numeric format directives, replaces ASCII digits
758 with the 'outdigits' defined in the LC_CTYPE locale facet. This is
759 used for Farsi (Persian) and maybe Arabic. */
765 /* Other system dependent strings are not valid. */
769 /* Initialize the codeset dependent parts of an opened message catalog.
770 Return the header entry. */
773 _nl_init_domain_conv (struct loaded_l10nfile
*domain_file
,
774 struct loaded_domain
*domain
,
775 struct binding
*domainbinding
)
777 /* Find out about the character set the file is encoded with.
778 This can be found (in textual form) in the entry "". If this
779 entry does not exist or if this does not contain the `charset='
780 information, we will assume the charset matches the one the
781 current locale and we don't have to perform any conversion. */
785 /* Preinitialize fields, to avoid recursion during _nl_find_msg. */
786 domain
->codeset_cntr
=
787 (domainbinding
!= NULL
? domainbinding
->codeset_cntr
: 0);
789 domain
->conv
= (__gconv_t
) -1;
792 domain
->conv
= (iconv_t
) -1;
795 domain
->conv_tab
= NULL
;
797 /* Get the header entry. */
798 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", &nullentrylen
);
800 if (nullentry
!= NULL
)
802 #if defined _LIBC || HAVE_ICONV
803 const char *charsetstr
;
805 charsetstr
= strstr (nullentry
, "charset=");
806 if (charsetstr
!= NULL
)
810 const char *outcharset
;
812 charsetstr
+= strlen ("charset=");
813 len
= strcspn (charsetstr
, " \t\n");
815 charset
= (char *) alloca (len
+ 1);
816 # if defined _LIBC || HAVE_MEMPCPY
817 *((char *) mempcpy (charset
, charsetstr
, len
)) = '\0';
819 memcpy (charset
, charsetstr
, len
);
823 /* The output charset should normally be determined by the
824 locale. But sometimes the locale is not used or not correctly
825 set up, so we provide a possibility for the user to override
826 this. Moreover, the value specified through
827 bind_textdomain_codeset overrides both. */
828 if (domainbinding
!= NULL
&& domainbinding
->codeset
!= NULL
)
829 outcharset
= domainbinding
->codeset
;
832 outcharset
= getenv ("OUTPUT_CHARSET");
833 if (outcharset
== NULL
|| outcharset
[0] == '\0')
836 outcharset
= _NL_CURRENT (LC_CTYPE
, CODESET
);
839 extern const char *locale_charset (void);
840 outcharset
= locale_charset ();
847 /* We always want to use transliteration. */
848 outcharset
= norm_add_slashes (outcharset
, "TRANSLIT");
849 charset
= norm_add_slashes (charset
, NULL
);
850 if (__gconv_open (outcharset
, charset
, &domain
->conv
,
853 domain
->conv
= (__gconv_t
) -1;
856 /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
857 we want to use transliteration. */
858 # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
859 || _LIBICONV_VERSION >= 0x0105
860 if (strchr (outcharset
, '/') == NULL
)
864 len
= strlen (outcharset
);
865 tmp
= (char *) alloca (len
+ 10 + 1);
866 memcpy (tmp
, outcharset
, len
);
867 memcpy (tmp
+ len
, "//TRANSLIT", 10 + 1);
870 domain
->conv
= iconv_open (outcharset
, charset
);
876 domain
->conv
= iconv_open (outcharset
, charset
);
882 #endif /* _LIBC || HAVE_ICONV */
888 /* Frees the codeset dependent parts of an opened message catalog. */
891 _nl_free_domain_conv (struct loaded_domain
*domain
)
893 if (domain
->conv_tab
!= NULL
&& domain
->conv_tab
!= (char **) -1)
894 free (domain
->conv_tab
);
897 if (domain
->conv
!= (__gconv_t
) -1)
898 __gconv_close (domain
->conv
);
901 if (domain
->conv
!= (iconv_t
) -1)
902 iconv_close (domain
->conv
);
907 /* Load the message catalogs specified by FILENAME. If it is no valid
908 message catalog do nothing. */
911 _nl_load_domain (struct loaded_l10nfile
*domain_file
,
912 struct binding
*domainbinding
)
921 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
923 struct loaded_domain
*domain
;
925 const char *nullentry
;
927 domain_file
->decided
= 1;
928 domain_file
->data
= NULL
;
930 /* Note that it would be useless to store domainbinding in domain_file
931 because domainbinding might be == NULL now but != NULL later (after
932 a call to bind_textdomain_codeset). */
934 /* If the record does not represent a valid locale the FILENAME
935 might be NULL. This can happen when according to the given
936 specification the locale file name is different for XPG and CEN
938 if (domain_file
->filename
== NULL
)
941 /* Try to open the addressed file. */
942 fd
= open (domain_file
->filename
, O_RDONLY
| O_BINARY
);
946 /* We must know about the size of the file. */
949 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
951 __builtin_expect (fstat (fd
, &st
) != 0, 0)
953 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
954 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
956 /* Something went wrong. */
962 /* Now we are ready to load the file. If mmap() is available we try
963 this first. If not available or it failed we try to load it. */
964 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
967 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
969 /* mmap() call was successful. */
975 /* If the data is not yet available (i.e. mmap'ed) we try to load
977 if (data
== (struct mo_file_header
*) -1)
982 data
= (struct mo_file_header
*) malloc (size
);
987 read_ptr
= (char *) data
;
990 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
994 if (nb
== -1 && errno
== EINTR
)
1003 while (to_read
> 0);
1008 /* Using the magic number we can test whether it really is a message
1010 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
1013 /* The magic number is wrong: not a message catalog file. */
1016 munmap ((caddr_t
) data
, size
);
1023 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
1026 domain_file
->data
= domain
;
1028 domain
->data
= (char *) data
;
1029 domain
->use_mmap
= use_mmap
;
1030 domain
->mmap_size
= size
;
1031 domain
->must_swap
= data
->magic
!= _MAGIC
;
1032 domain
->malloced
= NULL
;
1034 /* Fill in the information about the available tables. */
1035 revision
= W (domain
->must_swap
, data
->revision
);
1036 /* We support only the major revisions 0 and 1. */
1037 switch (revision
>> 16)
1041 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
1042 domain
->orig_tab
= (const struct string_desc
*)
1043 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
1044 domain
->trans_tab
= (const struct string_desc
*)
1045 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
1046 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
1048 (domain
->hash_size
> 2
1049 ? (const nls_uint32
*)
1050 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
1052 domain
->must_swap_hash_tab
= domain
->must_swap
;
1054 /* Now dispatch on the minor revision. */
1055 switch (revision
& 0xffff)
1058 domain
->n_sysdep_strings
= 0;
1059 domain
->orig_sysdep_tab
= NULL
;
1060 domain
->trans_sysdep_tab
= NULL
;
1065 nls_uint32 n_sysdep_strings
;
1067 if (domain
->hash_tab
== NULL
)
1068 /* This is invalid. These minor revisions need a hash table. */
1072 W (domain
->must_swap
, data
->n_sysdep_strings
);
1073 if (n_sysdep_strings
> 0)
1075 nls_uint32 n_sysdep_segments
;
1076 const struct sysdep_segment
*sysdep_segments
;
1077 const char **sysdep_segment_values
;
1078 const nls_uint32
*orig_sysdep_tab
;
1079 const nls_uint32
*trans_sysdep_tab
;
1080 nls_uint32 n_inmem_sysdep_strings
;
1083 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
1084 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
1085 nls_uint32
*inmem_hash_tab
;
1088 /* Get the values of the system dependent segments. */
1090 W (domain
->must_swap
, data
->n_sysdep_segments
);
1091 sysdep_segments
= (const struct sysdep_segment
*)
1093 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
1094 sysdep_segment_values
=
1095 alloca (n_sysdep_segments
* sizeof (const char *));
1096 for (i
= 0; i
< n_sysdep_segments
; i
++)
1100 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
1101 nls_uint32 namelen
=
1102 W (domain
->must_swap
, sysdep_segments
[i
].length
);
1104 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
1106 freea (sysdep_segment_values
);
1110 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
1113 orig_sysdep_tab
= (const nls_uint32
*)
1115 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1116 trans_sysdep_tab
= (const nls_uint32
*)
1118 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1120 /* Compute the amount of additional memory needed for the
1121 system dependent strings and the augmented hash table.
1122 At the same time, also drop string pairs which refer to
1123 an undefined system dependent segment. */
1124 n_inmem_sysdep_strings
= 0;
1125 memneed
= domain
->hash_size
* sizeof (nls_uint32
);
1126 for (i
= 0; i
< n_sysdep_strings
; i
++)
1131 for (j
= 0; j
< 2; j
++)
1133 const struct sysdep_string
*sysdep_string
=
1134 (const struct sysdep_string
*)
1136 + W (domain
->must_swap
,
1138 ? orig_sysdep_tab
[i
]
1139 : trans_sysdep_tab
[i
]));
1141 const struct segment_pair
*p
= sysdep_string
->segments
;
1143 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1144 for (p
= sysdep_string
->segments
;; p
++)
1146 nls_uint32 sysdepref
;
1148 need
+= W (domain
->must_swap
, p
->segsize
);
1150 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1151 if (sysdepref
== SEGMENTS_END
)
1154 if (sysdepref
>= n_sysdep_segments
)
1157 freea (sysdep_segment_values
);
1161 if (sysdep_segment_values
[sysdepref
] == NULL
)
1163 /* This particular string pair is invalid. */
1168 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1178 n_inmem_sysdep_strings
++;
1179 memneed
+= needs
[0] + needs
[1];
1182 memneed
+= 2 * n_inmem_sysdep_strings
1183 * sizeof (struct sysdep_string_desc
);
1185 if (n_inmem_sysdep_strings
> 0)
1189 /* Allocate additional memory. */
1190 mem
= (char *) malloc (memneed
);
1194 domain
->malloced
= mem
;
1195 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1196 mem
+= n_inmem_sysdep_strings
1197 * sizeof (struct sysdep_string_desc
);
1198 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1199 mem
+= n_inmem_sysdep_strings
1200 * sizeof (struct sysdep_string_desc
);
1201 inmem_hash_tab
= (nls_uint32
*) mem
;
1202 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1204 /* Compute the system dependent strings. */
1206 for (i
= 0; i
< n_sysdep_strings
; i
++)
1210 for (j
= 0; j
< 2; j
++)
1212 const struct sysdep_string
*sysdep_string
=
1213 (const struct sysdep_string
*)
1215 + W (domain
->must_swap
,
1217 ? orig_sysdep_tab
[i
]
1218 : trans_sysdep_tab
[i
]));
1219 const struct segment_pair
*p
=
1220 sysdep_string
->segments
;
1222 if (W (domain
->must_swap
, p
->sysdepref
)
1224 for (p
= sysdep_string
->segments
;; p
++)
1226 nls_uint32 sysdepref
;
1229 W (domain
->must_swap
, p
->sysdepref
);
1230 if (sysdepref
== SEGMENTS_END
)
1233 if (sysdep_segment_values
[sysdepref
] == NULL
)
1235 /* This particular string pair is
1248 for (j
= 0; j
< 2; j
++)
1250 const struct sysdep_string
*sysdep_string
=
1251 (const struct sysdep_string
*)
1253 + W (domain
->must_swap
,
1255 ? orig_sysdep_tab
[i
]
1256 : trans_sysdep_tab
[i
]));
1257 const char *static_segments
=
1259 + W (domain
->must_swap
, sysdep_string
->offset
);
1260 const struct segment_pair
*p
=
1261 sysdep_string
->segments
;
1263 /* Concatenate the segments, and fill
1264 inmem_orig_sysdep_tab[k] (for j == 0) and
1265 inmem_trans_sysdep_tab[k] (for j == 1). */
1267 struct sysdep_string_desc
*inmem_tab_entry
=
1269 ? inmem_orig_sysdep_tab
1270 : inmem_trans_sysdep_tab
)
1273 if (W (domain
->must_swap
, p
->sysdepref
)
1276 /* Only one static segment. */
1277 inmem_tab_entry
->length
=
1278 W (domain
->must_swap
, p
->segsize
);
1279 inmem_tab_entry
->pointer
= static_segments
;
1283 inmem_tab_entry
->pointer
= mem
;
1285 for (p
= sysdep_string
->segments
;; p
++)
1287 nls_uint32 segsize
=
1288 W (domain
->must_swap
, p
->segsize
);
1289 nls_uint32 sysdepref
=
1290 W (domain
->must_swap
, p
->sysdepref
);
1295 memcpy (mem
, static_segments
, segsize
);
1297 static_segments
+= segsize
;
1300 if (sysdepref
== SEGMENTS_END
)
1303 n
= strlen (sysdep_segment_values
[sysdepref
]);
1304 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1308 inmem_tab_entry
->length
=
1309 mem
- inmem_tab_entry
->pointer
;
1316 if (k
!= n_inmem_sysdep_strings
)
1319 /* Compute the augmented hash table. */
1320 for (i
= 0; i
< domain
->hash_size
; i
++)
1322 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1323 for (i
= 0; i
< n_inmem_sysdep_strings
; i
++)
1325 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1326 nls_uint32 hash_val
= hash_string (msgid
);
1327 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1329 1 + (hash_val
% (domain
->hash_size
- 2));
1333 if (inmem_hash_tab
[idx
] == 0)
1335 /* Hash table entry is empty. Use it. */
1336 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1340 if (idx
>= domain
->hash_size
- incr
)
1341 idx
-= domain
->hash_size
- incr
;
1347 domain
->n_sysdep_strings
= n_inmem_sysdep_strings
;
1348 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1349 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1351 domain
->hash_tab
= inmem_hash_tab
;
1352 domain
->must_swap_hash_tab
= 0;
1356 domain
->n_sysdep_strings
= 0;
1357 domain
->orig_sysdep_tab
= NULL
;
1358 domain
->trans_sysdep_tab
= NULL
;
1361 freea (sysdep_segment_values
);
1365 domain
->n_sysdep_strings
= 0;
1366 domain
->orig_sysdep_tab
= NULL
;
1367 domain
->trans_sysdep_tab
= NULL
;
1374 /* This is an invalid revision. */
1376 /* This is an invalid .mo file. */
1377 if (domain
->malloced
)
1378 free (domain
->malloced
);
1381 munmap ((caddr_t
) data
, size
);
1386 domain_file
->data
= NULL
;
1390 /* Now initialize the character set converter from the character set
1391 the file is encoded with (found in the header entry) to the domain's
1392 specified character set or the locale's character set. */
1393 nullentry
= _nl_init_domain_conv (domain_file
, domain
, domainbinding
);
1395 /* Also look for a plural specification. */
1396 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1403 _nl_unload_domain (struct loaded_domain
*domain
)
1405 if (domain
->plural
!= &__gettext_germanic_plural
)
1406 __gettext_free_exp (domain
->plural
);
1408 _nl_free_domain_conv (domain
);
1410 if (domain
->malloced
)
1411 free (domain
->malloced
);
1413 # ifdef _POSIX_MAPPED_FILES
1414 if (domain
->use_mmap
)
1415 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1417 # endif /* _POSIX_MAPPED_FILES */
1418 free ((void *) domain
->data
);