1 /* Load needed message catalogs.
2 Copyright (C) 1995-1999, 2000-2005 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"
94 # include <not-cancel.h>
97 /* Handle multi-threaded applications. */
99 # include <bits/libc-lock.h>
104 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
105 Note that our fallback values need not be literal strings, because we don't
106 use them with preprocessor string concatenation. */
107 #if !defined PRId8 || PRI_MACROS_BROKEN
111 #if !defined PRIi8 || PRI_MACROS_BROKEN
115 #if !defined PRIo8 || PRI_MACROS_BROKEN
119 #if !defined PRIu8 || PRI_MACROS_BROKEN
123 #if !defined PRIx8 || PRI_MACROS_BROKEN
127 #if !defined PRIX8 || PRI_MACROS_BROKEN
131 #if !defined PRId16 || PRI_MACROS_BROKEN
135 #if !defined PRIi16 || PRI_MACROS_BROKEN
139 #if !defined PRIo16 || PRI_MACROS_BROKEN
143 #if !defined PRIu16 || PRI_MACROS_BROKEN
147 #if !defined PRIx16 || PRI_MACROS_BROKEN
151 #if !defined PRIX16 || PRI_MACROS_BROKEN
155 #if !defined PRId32 || PRI_MACROS_BROKEN
159 #if !defined PRIi32 || PRI_MACROS_BROKEN
163 #if !defined PRIo32 || PRI_MACROS_BROKEN
167 #if !defined PRIu32 || PRI_MACROS_BROKEN
171 #if !defined PRIx32 || PRI_MACROS_BROKEN
175 #if !defined PRIX32 || PRI_MACROS_BROKEN
179 #if !defined PRId64 || PRI_MACROS_BROKEN
181 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
183 #if !defined PRIi64 || PRI_MACROS_BROKEN
185 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
187 #if !defined PRIo64 || PRI_MACROS_BROKEN
189 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
191 #if !defined PRIu64 || PRI_MACROS_BROKEN
193 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
195 #if !defined PRIx64 || PRI_MACROS_BROKEN
197 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
199 #if !defined PRIX64 || PRI_MACROS_BROKEN
201 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
203 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
205 # define PRIdLEAST8 "d"
207 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
209 # define PRIiLEAST8 "i"
211 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
213 # define PRIoLEAST8 "o"
215 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
217 # define PRIuLEAST8 "u"
219 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
221 # define PRIxLEAST8 "x"
223 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
225 # define PRIXLEAST8 "X"
227 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
229 # define PRIdLEAST16 "d"
231 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
233 # define PRIiLEAST16 "i"
235 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
237 # define PRIoLEAST16 "o"
239 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
241 # define PRIuLEAST16 "u"
243 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
245 # define PRIxLEAST16 "x"
247 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
249 # define PRIXLEAST16 "X"
251 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
253 # define PRIdLEAST32 "d"
255 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
257 # define PRIiLEAST32 "i"
259 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
261 # define PRIoLEAST32 "o"
263 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
265 # define PRIuLEAST32 "u"
267 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
269 # define PRIxLEAST32 "x"
271 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
273 # define PRIXLEAST32 "X"
275 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
277 # define PRIdLEAST64 PRId64
279 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
281 # define PRIiLEAST64 PRIi64
283 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
285 # define PRIoLEAST64 PRIo64
287 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
289 # define PRIuLEAST64 PRIu64
291 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
293 # define PRIxLEAST64 PRIx64
295 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
297 # define PRIXLEAST64 PRIX64
299 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
301 # define PRIdFAST8 "d"
303 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
305 # define PRIiFAST8 "i"
307 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
309 # define PRIoFAST8 "o"
311 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
313 # define PRIuFAST8 "u"
315 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
317 # define PRIxFAST8 "x"
319 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
321 # define PRIXFAST8 "X"
323 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
325 # define PRIdFAST16 "d"
327 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
329 # define PRIiFAST16 "i"
331 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
333 # define PRIoFAST16 "o"
335 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
337 # define PRIuFAST16 "u"
339 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
341 # define PRIxFAST16 "x"
343 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
345 # define PRIXFAST16 "X"
347 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
349 # define PRIdFAST32 "d"
351 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
353 # define PRIiFAST32 "i"
355 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
357 # define PRIoFAST32 "o"
359 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
361 # define PRIuFAST32 "u"
363 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
365 # define PRIxFAST32 "x"
367 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
369 # define PRIXFAST32 "X"
371 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
373 # define PRIdFAST64 PRId64
375 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
377 # define PRIiFAST64 PRIi64
379 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
381 # define PRIoFAST64 PRIo64
383 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
385 # define PRIuFAST64 PRIu64
387 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
389 # define PRIxFAST64 PRIx64
391 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
393 # define PRIXFAST64 PRIX64
395 #if !defined PRIdMAX || PRI_MACROS_BROKEN
397 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
399 #if !defined PRIiMAX || PRI_MACROS_BROKEN
401 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
403 #if !defined PRIoMAX || PRI_MACROS_BROKEN
405 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
407 #if !defined PRIuMAX || PRI_MACROS_BROKEN
409 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
411 #if !defined PRIxMAX || PRI_MACROS_BROKEN
413 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
415 #if !defined PRIXMAX || PRI_MACROS_BROKEN
417 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
419 #if !defined PRIdPTR || PRI_MACROS_BROKEN
422 (sizeof (void *) == sizeof (long) ? "ld" : \
423 sizeof (void *) == sizeof (int) ? "d" : \
426 #if !defined PRIiPTR || PRI_MACROS_BROKEN
429 (sizeof (void *) == sizeof (long) ? "li" : \
430 sizeof (void *) == sizeof (int) ? "i" : \
433 #if !defined PRIoPTR || PRI_MACROS_BROKEN
436 (sizeof (void *) == sizeof (long) ? "lo" : \
437 sizeof (void *) == sizeof (int) ? "o" : \
440 #if !defined PRIuPTR || PRI_MACROS_BROKEN
443 (sizeof (void *) == sizeof (long) ? "lu" : \
444 sizeof (void *) == sizeof (int) ? "u" : \
447 #if !defined PRIxPTR || PRI_MACROS_BROKEN
450 (sizeof (void *) == sizeof (long) ? "lx" : \
451 sizeof (void *) == sizeof (int) ? "x" : \
454 #if !defined PRIXPTR || PRI_MACROS_BROKEN
457 (sizeof (void *) == sizeof (long) ? "lX" : \
458 sizeof (void *) == sizeof (int) ? "X" : \
462 /* @@ end of prolog @@ */
465 /* Rename the non ISO C functions. This is required by the standard
466 because some ISO C functions will require linking with this object
467 file and the name space must not be polluted. */
468 # define open(name, flags) open_not_cancel_2 (name, flags)
469 # define close(fd) close_not_cancel_no_status (fd)
470 # define read(fd, buf, n) read_not_cancel (fd, buf, n)
471 # define mmap(addr, len, prot, flags, fd, offset) \
472 __mmap (addr, len, prot, flags, fd, offset)
473 # define munmap(addr, len) __munmap (addr, len)
476 /* For those losing systems which don't have `alloca' we have to add
477 some additional code emulating it. */
479 # define freea(p) /* nothing */
481 # define alloca(n) malloc (n)
482 # define freea(p) free (p)
485 /* For systems that distinguish between text and binary I/O.
486 O_BINARY is usually declared in <fcntl.h>. */
487 #if !defined O_BINARY && defined _O_BINARY
488 /* For MSC-compatible compilers. */
489 # define O_BINARY _O_BINARY
490 # define O_TEXT _O_TEXT
493 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
497 /* On reasonable systems, binary I/O is the default. */
503 /* We need a sign, whether a new catalog was loaded, which can be associated
504 with all translations. This is important if the translations are
505 cached by one of GCC's features. */
506 int _nl_msg_cat_cntr
;
509 /* Expand a system dependent string segment. Return NULL if unsupported. */
511 get_sysdep_segment_value (const char *name
)
513 /* Test for an ISO C 99 section 7.8.1 format string directive.
515 P R I { d | i | o | u | x | X }
516 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
517 /* We don't use a table of 14 times 6 'const char *' strings here, because
518 data relocations cost startup time. */
519 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
521 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
522 || name
[3] == 'x' || name
[3] == 'X')
524 if (name
[4] == '8' && name
[5] == '\0')
540 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
556 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
572 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
588 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
589 && name
[7] == 'S' && name
[8] == 'T')
591 if (name
[9] == '8' && name
[10] == '\0')
607 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
623 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
639 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
656 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
659 if (name
[8] == '8' && name
[9] == '\0')
675 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
691 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
707 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
724 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
741 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
760 /* Test for a glibc specific printf() format directive flag. */
761 if (name
[0] == 'I' && name
[1] == '\0')
763 #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
764 /* The 'I' flag, in numeric format directives, replaces ASCII digits
765 with the 'outdigits' defined in the LC_CTYPE locale facet. This is
766 used for Farsi (Persian) and maybe Arabic. */
772 /* Other system dependent strings are not valid. */
776 /* Load the message catalogs specified by FILENAME. If it is no valid
777 message catalog do nothing. */
780 _nl_load_domain (struct loaded_l10nfile
*domain_file
,
781 struct binding
*domainbinding
)
783 __libc_lock_define_initialized_recursive (static, lock
)
791 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
793 struct loaded_domain
*domain
;
795 const char *nullentry
;
798 __libc_lock_lock_recursive (lock
);
799 if (domain_file
->decided
!= 0)
801 /* There are two possibilities:
803 + this is the same thread calling again during this initialization
804 via _nl_find_msg. We have initialized everything this call needs.
806 + this is another thread which tried to initialize this object.
807 Not necessary anymore since if the lock is available this
813 domain_file
->decided
= -1;
814 domain_file
->data
= NULL
;
816 /* Note that it would be useless to store domainbinding in domain_file
817 because domainbinding might be == NULL now but != NULL later (after
818 a call to bind_textdomain_codeset). */
820 /* If the record does not represent a valid locale the FILENAME
821 might be NULL. This can happen when according to the given
822 specification the locale file name is different for XPG and CEN
824 if (domain_file
->filename
== NULL
)
827 /* Try to open the addressed file. */
828 fd
= open (domain_file
->filename
, O_RDONLY
| O_BINARY
);
832 /* We must know about the size of the file. */
835 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
837 __builtin_expect (fstat (fd
, &st
) != 0, 0)
839 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
840 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
841 /* Something went wrong. */
845 /* Now we are ready to load the file. If mmap() is available we try
846 this first. If not available or it failed we try to load it. */
847 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
850 if (__builtin_expect (data
!= (struct mo_file_header
*) -1, 1))
852 /* mmap() call was successful. */
859 /* If the data is not yet available (i.e. mmap'ed) we try to load
861 if (data
== (struct mo_file_header
*) -1)
866 data
= (struct mo_file_header
*) malloc (size
);
871 read_ptr
= (char *) data
;
874 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
878 if (nb
== -1 && errno
== EINTR
)
892 /* Using the magic number we can test whether it really is a message
894 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
897 /* The magic number is wrong: not a message catalog file. */
900 munmap ((caddr_t
) data
, size
);
907 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
910 domain_file
->data
= domain
;
912 domain
->data
= (char *) data
;
913 domain
->use_mmap
= use_mmap
;
914 domain
->mmap_size
= size
;
915 domain
->must_swap
= data
->magic
!= _MAGIC
;
916 domain
->malloced
= NULL
;
918 /* Fill in the information about the available tables. */
919 revision
= W (domain
->must_swap
, data
->revision
);
920 /* We support only the major revisions 0 and 1. */
921 switch (revision
>> 16)
925 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
926 domain
->orig_tab
= (const struct string_desc
*)
927 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
928 domain
->trans_tab
= (const struct string_desc
*)
929 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
930 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
932 (domain
->hash_size
> 2
933 ? (const nls_uint32
*)
934 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
936 domain
->must_swap_hash_tab
= domain
->must_swap
;
938 /* Now dispatch on the minor revision. */
939 switch (revision
& 0xffff)
942 domain
->n_sysdep_strings
= 0;
943 domain
->orig_sysdep_tab
= NULL
;
944 domain
->trans_sysdep_tab
= NULL
;
949 nls_uint32 n_sysdep_strings
;
951 if (domain
->hash_tab
== NULL
)
952 /* This is invalid. These minor revisions need a hash table. */
956 W (domain
->must_swap
, data
->n_sysdep_strings
);
957 if (n_sysdep_strings
> 0)
959 nls_uint32 n_sysdep_segments
;
960 const struct sysdep_segment
*sysdep_segments
;
961 const char **sysdep_segment_values
;
962 const nls_uint32
*orig_sysdep_tab
;
963 const nls_uint32
*trans_sysdep_tab
;
964 nls_uint32 n_inmem_sysdep_strings
;
967 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
968 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
969 nls_uint32
*inmem_hash_tab
;
972 /* Get the values of the system dependent segments. */
974 W (domain
->must_swap
, data
->n_sysdep_segments
);
975 sysdep_segments
= (const struct sysdep_segment
*)
977 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
978 sysdep_segment_values
=
979 alloca (n_sysdep_segments
* sizeof (const char *));
980 for (i
= 0; i
< n_sysdep_segments
; i
++)
984 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
986 W (domain
->must_swap
, sysdep_segments
[i
].length
);
988 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
990 freea (sysdep_segment_values
);
994 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
997 orig_sysdep_tab
= (const nls_uint32
*)
999 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
1000 trans_sysdep_tab
= (const nls_uint32
*)
1002 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
1004 /* Compute the amount of additional memory needed for the
1005 system dependent strings and the augmented hash table.
1006 At the same time, also drop string pairs which refer to
1007 an undefined system dependent segment. */
1008 n_inmem_sysdep_strings
= 0;
1009 memneed
= domain
->hash_size
* sizeof (nls_uint32
);
1010 for (i
= 0; i
< n_sysdep_strings
; i
++)
1015 for (j
= 0; j
< 2; j
++)
1017 const struct sysdep_string
*sysdep_string
=
1018 (const struct sysdep_string
*)
1020 + W (domain
->must_swap
,
1022 ? orig_sysdep_tab
[i
]
1023 : trans_sysdep_tab
[i
]));
1025 const struct segment_pair
*p
= sysdep_string
->segments
;
1027 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1028 for (p
= sysdep_string
->segments
;; p
++)
1030 nls_uint32 sysdepref
;
1032 need
+= W (domain
->must_swap
, p
->segsize
);
1034 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1035 if (sysdepref
== SEGMENTS_END
)
1038 if (sysdepref
>= n_sysdep_segments
)
1041 freea (sysdep_segment_values
);
1045 if (sysdep_segment_values
[sysdepref
] == NULL
)
1047 /* This particular string pair is invalid. */
1052 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1062 n_inmem_sysdep_strings
++;
1063 memneed
+= needs
[0] + needs
[1];
1066 memneed
+= 2 * n_inmem_sysdep_strings
1067 * sizeof (struct sysdep_string_desc
);
1069 if (n_inmem_sysdep_strings
> 0)
1073 /* Allocate additional memory. */
1074 mem
= (char *) malloc (memneed
);
1078 domain
->malloced
= mem
;
1079 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1080 mem
+= n_inmem_sysdep_strings
1081 * sizeof (struct sysdep_string_desc
);
1082 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1083 mem
+= n_inmem_sysdep_strings
1084 * sizeof (struct sysdep_string_desc
);
1085 inmem_hash_tab
= (nls_uint32
*) mem
;
1086 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1088 /* Compute the system dependent strings. */
1090 for (i
= 0; i
< n_sysdep_strings
; i
++)
1094 for (j
= 0; j
< 2; j
++)
1096 const struct sysdep_string
*sysdep_string
=
1097 (const struct sysdep_string
*)
1099 + W (domain
->must_swap
,
1101 ? orig_sysdep_tab
[i
]
1102 : trans_sysdep_tab
[i
]));
1103 const struct segment_pair
*p
=
1104 sysdep_string
->segments
;
1106 if (W (domain
->must_swap
, p
->sysdepref
)
1108 for (p
= sysdep_string
->segments
;; p
++)
1110 nls_uint32 sysdepref
;
1113 W (domain
->must_swap
, p
->sysdepref
);
1114 if (sysdepref
== SEGMENTS_END
)
1117 if (sysdep_segment_values
[sysdepref
] == NULL
)
1119 /* This particular string pair is
1132 for (j
= 0; j
< 2; j
++)
1134 const struct sysdep_string
*sysdep_string
=
1135 (const struct sysdep_string
*)
1137 + W (domain
->must_swap
,
1139 ? orig_sysdep_tab
[i
]
1140 : trans_sysdep_tab
[i
]));
1141 const char *static_segments
=
1143 + W (domain
->must_swap
, sysdep_string
->offset
);
1144 const struct segment_pair
*p
=
1145 sysdep_string
->segments
;
1147 /* Concatenate the segments, and fill
1148 inmem_orig_sysdep_tab[k] (for j == 0) and
1149 inmem_trans_sysdep_tab[k] (for j == 1). */
1151 struct sysdep_string_desc
*inmem_tab_entry
=
1153 ? inmem_orig_sysdep_tab
1154 : inmem_trans_sysdep_tab
)
1157 if (W (domain
->must_swap
, p
->sysdepref
)
1160 /* Only one static segment. */
1161 inmem_tab_entry
->length
=
1162 W (domain
->must_swap
, p
->segsize
);
1163 inmem_tab_entry
->pointer
= static_segments
;
1167 inmem_tab_entry
->pointer
= mem
;
1169 for (p
= sysdep_string
->segments
;; p
++)
1171 nls_uint32 segsize
=
1172 W (domain
->must_swap
, p
->segsize
);
1173 nls_uint32 sysdepref
=
1174 W (domain
->must_swap
, p
->sysdepref
);
1179 memcpy (mem
, static_segments
, segsize
);
1181 static_segments
+= segsize
;
1184 if (sysdepref
== SEGMENTS_END
)
1187 n
= strlen (sysdep_segment_values
[sysdepref
]);
1188 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1192 inmem_tab_entry
->length
=
1193 mem
- inmem_tab_entry
->pointer
;
1200 if (k
!= n_inmem_sysdep_strings
)
1203 /* Compute the augmented hash table. */
1204 for (i
= 0; i
< domain
->hash_size
; i
++)
1206 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1207 for (i
= 0; i
< n_inmem_sysdep_strings
; i
++)
1209 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1210 nls_uint32 hash_val
= __hash_string (msgid
);
1211 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1213 1 + (hash_val
% (domain
->hash_size
- 2));
1217 if (inmem_hash_tab
[idx
] == 0)
1219 /* Hash table entry is empty. Use it. */
1220 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1224 if (idx
>= domain
->hash_size
- incr
)
1225 idx
-= domain
->hash_size
- incr
;
1231 domain
->n_sysdep_strings
= n_inmem_sysdep_strings
;
1232 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1233 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1235 domain
->hash_tab
= inmem_hash_tab
;
1236 domain
->must_swap_hash_tab
= 0;
1240 domain
->n_sysdep_strings
= 0;
1241 domain
->orig_sysdep_tab
= NULL
;
1242 domain
->trans_sysdep_tab
= NULL
;
1245 freea (sysdep_segment_values
);
1249 domain
->n_sysdep_strings
= 0;
1250 domain
->orig_sysdep_tab
= NULL
;
1251 domain
->trans_sysdep_tab
= NULL
;
1258 /* This is an invalid revision. */
1260 /* This is an invalid .mo file. */
1261 if (domain
->malloced
)
1262 free (domain
->malloced
);
1265 munmap ((caddr_t
) data
, size
);
1270 domain_file
->data
= NULL
;
1274 /* No caches of converted translations so far. */
1275 domain
->conversions
= NULL
;
1276 domain
->nconversions
= 0;
1278 /* Get the header entry and look for a plural specification. */
1279 #ifdef IN_LIBGLOCALE
1281 _nl_find_msg (domain_file
, domainbinding
, NULL
, "", &nullentrylen
);
1283 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", 0, &nullentrylen
);
1285 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1291 domain_file
->decided
= 1;
1294 __libc_lock_unlock_recursive (lock
);
1300 internal_function __libc_freeres_fn_section
1301 _nl_unload_domain (struct loaded_domain
*domain
)
1305 if (domain
->plural
!= &__gettext_germanic_plural
)
1306 __gettext_free_exp (domain
->plural
);
1308 for (i
= 0; i
< domain
->nconversions
; i
++)
1310 struct converted_domain
*convd
= &domain
->conversions
[i
];
1312 free (convd
->encoding
);
1313 if (convd
->conv_tab
!= NULL
&& convd
->conv_tab
!= (char **) -1)
1314 free (convd
->conv_tab
);
1315 if (convd
->conv
!= (__gconv_t
) -1)
1316 __gconv_close (convd
->conv
);
1318 if (domain
->conversions
!= NULL
)
1319 free (domain
->conversions
);
1321 if (domain
->malloced
)
1322 free (domain
->malloced
);
1324 # ifdef _POSIX_MAPPED_FILES
1325 if (domain
->use_mmap
)
1326 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1328 # endif /* _POSIX_MAPPED_FILES */
1329 free ((void *) domain
->data
);