1 /* Load needed message catalogs.
2 Copyright (C) 1995-2013 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, see
17 <http://www.gnu.org/licenses/>. */
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
34 #include <sys/types.h>
39 # define alloca __builtin_alloca
40 # define HAVE_ALLOCA 1
42 # if defined HAVE_ALLOCA_H || defined _LIBC
58 #if defined HAVE_UNISTD_H || defined _LIBC
63 # include <langinfo.h>
67 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
68 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
69 # include <sys/mman.h>
76 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
79 #if defined HAVE_INTTYPES_H || defined _LIBC
80 # include <inttypes.h>
85 #include "hash-string.h"
86 #include "plural-exp.h"
89 # include "../locale/localeinfo.h"
90 # include <not-cancel.h>
91 # include <bits/libc-lock.h>
94 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
95 Note that our fallback values need not be literal strings, because we don't
96 use them with preprocessor string concatenation. */
97 #if !defined PRId8 || PRI_MACROS_BROKEN
101 #if !defined PRIi8 || PRI_MACROS_BROKEN
105 #if !defined PRIo8 || PRI_MACROS_BROKEN
109 #if !defined PRIu8 || PRI_MACROS_BROKEN
113 #if !defined PRIx8 || PRI_MACROS_BROKEN
117 #if !defined PRIX8 || PRI_MACROS_BROKEN
121 #if !defined PRId16 || PRI_MACROS_BROKEN
125 #if !defined PRIi16 || PRI_MACROS_BROKEN
129 #if !defined PRIo16 || PRI_MACROS_BROKEN
133 #if !defined PRIu16 || PRI_MACROS_BROKEN
137 #if !defined PRIx16 || PRI_MACROS_BROKEN
141 #if !defined PRIX16 || PRI_MACROS_BROKEN
145 #if !defined PRId32 || PRI_MACROS_BROKEN
149 #if !defined PRIi32 || PRI_MACROS_BROKEN
153 #if !defined PRIo32 || PRI_MACROS_BROKEN
157 #if !defined PRIu32 || PRI_MACROS_BROKEN
161 #if !defined PRIx32 || PRI_MACROS_BROKEN
165 #if !defined PRIX32 || PRI_MACROS_BROKEN
169 #if !defined PRId64 || PRI_MACROS_BROKEN
171 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
173 #if !defined PRIi64 || PRI_MACROS_BROKEN
175 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
177 #if !defined PRIo64 || PRI_MACROS_BROKEN
179 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
181 #if !defined PRIu64 || PRI_MACROS_BROKEN
183 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
185 #if !defined PRIx64 || PRI_MACROS_BROKEN
187 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
189 #if !defined PRIX64 || PRI_MACROS_BROKEN
191 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
193 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
195 # define PRIdLEAST8 "d"
197 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
199 # define PRIiLEAST8 "i"
201 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
203 # define PRIoLEAST8 "o"
205 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
207 # define PRIuLEAST8 "u"
209 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
211 # define PRIxLEAST8 "x"
213 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
215 # define PRIXLEAST8 "X"
217 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
219 # define PRIdLEAST16 "d"
221 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
223 # define PRIiLEAST16 "i"
225 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
227 # define PRIoLEAST16 "o"
229 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
231 # define PRIuLEAST16 "u"
233 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
235 # define PRIxLEAST16 "x"
237 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
239 # define PRIXLEAST16 "X"
241 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
243 # define PRIdLEAST32 "d"
245 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
247 # define PRIiLEAST32 "i"
249 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
251 # define PRIoLEAST32 "o"
253 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
255 # define PRIuLEAST32 "u"
257 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
259 # define PRIxLEAST32 "x"
261 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
263 # define PRIXLEAST32 "X"
265 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
267 # define PRIdLEAST64 PRId64
269 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
271 # define PRIiLEAST64 PRIi64
273 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
275 # define PRIoLEAST64 PRIo64
277 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
279 # define PRIuLEAST64 PRIu64
281 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
283 # define PRIxLEAST64 PRIx64
285 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
287 # define PRIXLEAST64 PRIX64
289 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
291 # define PRIdFAST8 "d"
293 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
295 # define PRIiFAST8 "i"
297 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
299 # define PRIoFAST8 "o"
301 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
303 # define PRIuFAST8 "u"
305 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
307 # define PRIxFAST8 "x"
309 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
311 # define PRIXFAST8 "X"
313 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
315 # define PRIdFAST16 "d"
317 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
319 # define PRIiFAST16 "i"
321 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
323 # define PRIoFAST16 "o"
325 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
327 # define PRIuFAST16 "u"
329 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
331 # define PRIxFAST16 "x"
333 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
335 # define PRIXFAST16 "X"
337 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
339 # define PRIdFAST32 "d"
341 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
343 # define PRIiFAST32 "i"
345 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
347 # define PRIoFAST32 "o"
349 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
351 # define PRIuFAST32 "u"
353 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
355 # define PRIxFAST32 "x"
357 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
359 # define PRIXFAST32 "X"
361 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
363 # define PRIdFAST64 PRId64
365 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
367 # define PRIiFAST64 PRIi64
369 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
371 # define PRIoFAST64 PRIo64
373 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
375 # define PRIuFAST64 PRIu64
377 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
379 # define PRIxFAST64 PRIx64
381 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
383 # define PRIXFAST64 PRIX64
385 #if !defined PRIdMAX || PRI_MACROS_BROKEN
387 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
389 #if !defined PRIiMAX || PRI_MACROS_BROKEN
391 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
393 #if !defined PRIoMAX || PRI_MACROS_BROKEN
395 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
397 #if !defined PRIuMAX || PRI_MACROS_BROKEN
399 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
401 #if !defined PRIxMAX || PRI_MACROS_BROKEN
403 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
405 #if !defined PRIXMAX || PRI_MACROS_BROKEN
407 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
409 #if !defined PRIdPTR || PRI_MACROS_BROKEN
412 (sizeof (void *) == sizeof (long) ? "ld" : \
413 sizeof (void *) == sizeof (int) ? "d" : \
416 #if !defined PRIiPTR || PRI_MACROS_BROKEN
419 (sizeof (void *) == sizeof (long) ? "li" : \
420 sizeof (void *) == sizeof (int) ? "i" : \
423 #if !defined PRIoPTR || PRI_MACROS_BROKEN
426 (sizeof (void *) == sizeof (long) ? "lo" : \
427 sizeof (void *) == sizeof (int) ? "o" : \
430 #if !defined PRIuPTR || PRI_MACROS_BROKEN
433 (sizeof (void *) == sizeof (long) ? "lu" : \
434 sizeof (void *) == sizeof (int) ? "u" : \
437 #if !defined PRIxPTR || PRI_MACROS_BROKEN
440 (sizeof (void *) == sizeof (long) ? "lx" : \
441 sizeof (void *) == sizeof (int) ? "x" : \
444 #if !defined PRIXPTR || PRI_MACROS_BROKEN
447 (sizeof (void *) == sizeof (long) ? "lX" : \
448 sizeof (void *) == sizeof (int) ? "X" : \
452 /* @@ end of prolog @@ */
455 /* Rename the non ISO C functions. This is required by the standard
456 because some ISO C functions will require linking with this object
457 file and the name space must not be polluted. */
458 # define open(name, flags) open_not_cancel_2 (name, flags)
459 # define close(fd) close_not_cancel_no_status (fd)
460 # define read(fd, buf, n) read_not_cancel (fd, buf, n)
461 # define mmap(addr, len, prot, flags, fd, offset) \
462 __mmap (addr, len, prot, flags, fd, offset)
463 # define munmap(addr, len) __munmap (addr, len)
466 /* For those losing systems which don't have `alloca' we have to add
467 some additional code emulating it. */
469 # define freea(p) /* nothing */
471 # define alloca(n) malloc (n)
472 # define freea(p) free (p)
476 /* Prototypes for local functions. Needed to ensure compiler checking of
477 function argument counts despite of K&R C function definition syntax. */
478 static const char *get_sysdep_segment_value
PARAMS ((const char *name
));
481 /* We need a sign, whether a new catalog was loaded, which can be associated
482 with all translations. This is important if the translations are
483 cached by one of GCC's features. */
484 int _nl_msg_cat_cntr
;
487 /* Expand a system dependent string segment. Return NULL if unsupported. */
489 get_sysdep_segment_value (name
)
492 /* Test for an ISO C 99 section 7.8.1 format string directive.
494 P R I { d | i | o | u | x | X }
495 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
496 /* We don't use a table of 14 times 6 'const char *' strings here, because
497 data relocations cost startup time. */
498 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
500 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
501 || name
[3] == 'x' || name
[3] == 'X')
503 if (name
[4] == '8' && name
[5] == '\0')
519 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
535 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
551 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
567 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
568 && name
[7] == 'S' && name
[8] == 'T')
570 if (name
[9] == '8' && name
[10] == '\0')
586 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
602 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
618 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
635 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
638 if (name
[8] == '8' && name
[9] == '\0')
654 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
670 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
686 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
703 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
720 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
739 /* Test for a glibc specific printf() format directive flag. */
740 if (name
[0] == 'I' && name
[1] == '\0')
742 #if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)
743 /* The 'I' flag, in numeric format directives, replaces ASCII digits
744 with the 'outdigits' defined in the LC_CTYPE locale facet. This is
745 used for Farsi (Persian) and maybe Arabic. */
751 /* Other system dependent strings are not valid. */
755 /* Load the message catalogs specified by FILENAME. If it is no valid
756 message catalog do nothing. */
759 _nl_load_domain (domain_file
, domainbinding
)
760 struct loaded_l10nfile
*domain_file
;
761 struct binding
*domainbinding
;
763 __libc_lock_define_initialized_recursive (static, lock
);
771 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
773 struct loaded_domain
*domain
;
775 const char *nullentry
;
778 __libc_lock_lock_recursive (lock
);
779 if (domain_file
->decided
!= 0)
781 /* There are two possibilities:
783 + is is the same thread calling again during this
784 initialization via _nl_find_msg. We have initialized
785 everything this call needs.
787 + this is another thread which tried to initialize this object.
788 Not necessary anymore since if the lock is available this
791 __libc_lock_unlock_recursive (lock
);
795 domain_file
->decided
= -1;
796 domain_file
->data
= NULL
;
798 /* Note that it would be useless to store domainbinding in domain_file
799 because domainbinding might be == NULL now but != NULL later (after
800 a call to bind_textdomain_codeset). */
802 /* If the record does not represent a valid locale the FILENAME
803 might be NULL. This can happen when according to the given
804 specification the locale file name is different for XPG and CEN
806 if (domain_file
->filename
== NULL
)
809 /* Try to open the addressed file. */
810 fd
= open (domain_file
->filename
, O_RDONLY
);
814 /* We must know about the size of the file. */
817 __builtin_expect (fstat64 (fd
, &st
) != 0, 0)
819 __builtin_expect (fstat (fd
, &st
) != 0, 0)
821 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
822 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
823 /* Something went wrong. */
827 /* Now we are ready to load the file. If mmap() is available we try
828 this first. If not available or it failed we try to load it. */
829 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
832 if (__builtin_expect (data
!= MAP_FAILED
, 1))
834 /* mmap() call was successful. */
840 assert (MAP_FAILED
== (void *) -1);
843 /* If the data is not yet available (i.e. mmap'ed) we try to load
845 if (data
== (struct mo_file_header
*) -1)
850 data
= (struct mo_file_header
*) malloc (size
);
855 read_ptr
= (char *) data
;
858 long int nb
= (long int) TEMP_FAILURE_RETRY (read (fd
, read_ptr
,
872 /* Using the magic number we can test whether it really is a message
874 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
877 /* The magic number is wrong: not a message catalog file. */
880 munmap ((caddr_t
) data
, size
);
887 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
890 domain_file
->data
= domain
;
892 domain
->data
= (char *) data
;
893 domain
->use_mmap
= use_mmap
;
894 domain
->mmap_size
= size
;
895 domain
->must_swap
= data
->magic
!= _MAGIC
;
896 domain
->malloced
= NULL
;
898 /* Fill in the information about the available tables. */
899 revision
= W (domain
->must_swap
, data
->revision
);
900 /* We support only the major revisions 0 and 1. */
901 switch (revision
>> 16)
905 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
906 domain
->orig_tab
= (const struct string_desc
*)
907 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
908 domain
->trans_tab
= (const struct string_desc
*)
909 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
910 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
912 (domain
->hash_size
> 2
913 ? (const nls_uint32
*)
914 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
916 domain
->must_swap_hash_tab
= domain
->must_swap
;
918 /* Now dispatch on the minor revision. */
919 switch (revision
& 0xffff)
922 domain
->n_sysdep_strings
= 0;
923 domain
->orig_sysdep_tab
= NULL
;
924 domain
->trans_sysdep_tab
= NULL
;
929 nls_uint32 n_sysdep_strings
;
931 if (domain
->hash_tab
== NULL
)
932 /* This is invalid. These minor revisions need a hash table. */
936 W (domain
->must_swap
, data
->n_sysdep_strings
);
937 if (n_sysdep_strings
> 0)
939 nls_uint32 n_sysdep_segments
;
940 const struct sysdep_segment
*sysdep_segments
;
941 const char **sysdep_segment_values
;
942 const nls_uint32
*orig_sysdep_tab
;
943 const nls_uint32
*trans_sysdep_tab
;
944 nls_uint32 n_inmem_sysdep_strings
;
947 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
948 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
949 nls_uint32
*inmem_hash_tab
;
952 /* Get the values of the system dependent segments. */
954 W (domain
->must_swap
, data
->n_sysdep_segments
);
955 sysdep_segments
= (const struct sysdep_segment
*)
957 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
958 sysdep_segment_values
=
959 alloca (n_sysdep_segments
* sizeof (const char *));
960 for (i
= 0; i
< n_sysdep_segments
; i
++)
964 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
966 W (domain
->must_swap
, sysdep_segments
[i
].length
);
968 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
970 freea (sysdep_segment_values
);
974 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
977 orig_sysdep_tab
= (const nls_uint32
*)
979 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
980 trans_sysdep_tab
= (const nls_uint32
*)
982 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
984 /* Compute the amount of additional memory needed for the
985 system dependent strings and the augmented hash table.
986 At the same time, also drop string pairs which refer to
987 an undefined system dependent segment. */
988 n_inmem_sysdep_strings
= 0;
989 memneed
= domain
->hash_size
* sizeof (nls_uint32
);
990 for (i
= 0; i
< n_sysdep_strings
; i
++)
995 for (j
= 0; j
< 2; j
++)
997 const struct sysdep_string
*sysdep_string
=
998 (const struct sysdep_string
*)
1000 + W (domain
->must_swap
,
1002 ? orig_sysdep_tab
[i
]
1003 : trans_sysdep_tab
[i
]));
1005 const struct segment_pair
*p
= sysdep_string
->segments
;
1007 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1008 for (p
= sysdep_string
->segments
;; p
++)
1010 nls_uint32 sysdepref
;
1012 need
+= W (domain
->must_swap
, p
->segsize
);
1014 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1015 if (sysdepref
== SEGMENTS_END
)
1018 if (sysdepref
>= n_sysdep_segments
)
1021 freea (sysdep_segment_values
);
1025 if (sysdep_segment_values
[sysdepref
] == NULL
)
1027 /* This particular string pair is invalid. */
1032 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1042 n_inmem_sysdep_strings
++;
1043 memneed
+= needs
[0] + needs
[1];
1046 memneed
+= 2 * n_inmem_sysdep_strings
1047 * sizeof (struct sysdep_string_desc
);
1049 if (n_inmem_sysdep_strings
> 0)
1053 /* Allocate additional memory. */
1054 mem
= (char *) malloc (memneed
);
1058 domain
->malloced
= mem
;
1059 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1060 mem
+= n_inmem_sysdep_strings
1061 * sizeof (struct sysdep_string_desc
);
1062 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1063 mem
+= n_inmem_sysdep_strings
1064 * sizeof (struct sysdep_string_desc
);
1065 inmem_hash_tab
= (nls_uint32
*) mem
;
1066 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1068 /* Compute the system dependent strings. */
1070 for (i
= 0; i
< n_sysdep_strings
; i
++)
1074 for (j
= 0; j
< 2; j
++)
1076 const struct sysdep_string
*sysdep_string
=
1077 (const struct sysdep_string
*)
1079 + W (domain
->must_swap
,
1081 ? orig_sysdep_tab
[i
]
1082 : trans_sysdep_tab
[i
]));
1083 const struct segment_pair
*p
=
1084 sysdep_string
->segments
;
1086 if (W (domain
->must_swap
, p
->sysdepref
)
1088 for (p
= sysdep_string
->segments
;; p
++)
1090 nls_uint32 sysdepref
;
1093 W (domain
->must_swap
, p
->sysdepref
);
1094 if (sysdepref
== SEGMENTS_END
)
1097 if (sysdep_segment_values
[sysdepref
] == NULL
)
1099 /* This particular string pair is
1112 for (j
= 0; j
< 2; j
++)
1114 const struct sysdep_string
*sysdep_string
=
1115 (const struct sysdep_string
*)
1117 + W (domain
->must_swap
,
1119 ? orig_sysdep_tab
[i
]
1120 : trans_sysdep_tab
[i
]));
1121 const char *static_segments
=
1123 + W (domain
->must_swap
, sysdep_string
->offset
);
1124 const struct segment_pair
*p
=
1125 sysdep_string
->segments
;
1127 /* Concatenate the segments, and fill
1128 inmem_orig_sysdep_tab[k] (for j == 0) and
1129 inmem_trans_sysdep_tab[k] (for j == 1). */
1131 struct sysdep_string_desc
*inmem_tab_entry
=
1133 ? inmem_orig_sysdep_tab
1134 : inmem_trans_sysdep_tab
)
1137 if (W (domain
->must_swap
, p
->sysdepref
)
1140 /* Only one static segment. */
1141 inmem_tab_entry
->length
=
1142 W (domain
->must_swap
, p
->segsize
);
1143 inmem_tab_entry
->pointer
= static_segments
;
1147 inmem_tab_entry
->pointer
= mem
;
1149 for (p
= sysdep_string
->segments
;; p
++)
1151 nls_uint32 segsize
=
1152 W (domain
->must_swap
, p
->segsize
);
1153 nls_uint32 sysdepref
=
1154 W (domain
->must_swap
, p
->sysdepref
);
1159 memcpy (mem
, static_segments
, segsize
);
1161 static_segments
+= segsize
;
1164 if (sysdepref
== SEGMENTS_END
)
1167 n
= strlen (sysdep_segment_values
[sysdepref
]);
1168 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1172 inmem_tab_entry
->length
=
1173 mem
- inmem_tab_entry
->pointer
;
1180 if (k
!= n_inmem_sysdep_strings
)
1183 /* Compute the augmented hash table. */
1184 for (i
= 0; i
< domain
->hash_size
; i
++)
1186 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1187 for (i
= 0; i
< n_inmem_sysdep_strings
; i
++)
1189 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1190 nls_uint32 hash_val
= __hash_string (msgid
);
1191 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1193 1 + (hash_val
% (domain
->hash_size
- 2));
1197 if (inmem_hash_tab
[idx
] == 0)
1199 /* Hash table entry is empty. Use it. */
1200 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1204 if (idx
>= domain
->hash_size
- incr
)
1205 idx
-= domain
->hash_size
- incr
;
1211 domain
->n_sysdep_strings
= n_inmem_sysdep_strings
;
1212 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1213 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1215 domain
->hash_tab
= inmem_hash_tab
;
1216 domain
->must_swap_hash_tab
= 0;
1220 domain
->n_sysdep_strings
= 0;
1221 domain
->orig_sysdep_tab
= NULL
;
1222 domain
->trans_sysdep_tab
= NULL
;
1225 freea (sysdep_segment_values
);
1229 domain
->n_sysdep_strings
= 0;
1230 domain
->orig_sysdep_tab
= NULL
;
1231 domain
->trans_sysdep_tab
= NULL
;
1238 /* This is an invalid revision. */
1240 /* This is an invalid .mo file or we ran out of resources. */
1241 free (domain
->malloced
);
1244 munmap ((caddr_t
) data
, size
);
1249 domain_file
->data
= NULL
;
1253 /* No caches of converted translations so far. */
1254 domain
->conversions
= NULL
;
1255 domain
->nconversions
= 0;
1256 __libc_rwlock_init (domain
->conversions_lock
);
1258 /* Get the header entry and look for a plural specification. */
1259 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", 0, &nullentrylen
);
1260 if (__builtin_expect (nullentry
== (char *) -1, 0))
1262 __libc_rwlock_fini (domain
->conversions_lock
);
1265 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1271 domain_file
->decided
= 1;
1273 __libc_lock_unlock_recursive (lock
);
1279 internal_function __libc_freeres_fn_section
1280 _nl_unload_domain (domain
)
1281 struct loaded_domain
*domain
;
1285 if (domain
->plural
!= &__gettext_germanic_plural
)
1286 __gettext_free_exp ((struct expression
*) domain
->plural
);
1288 for (i
= 0; i
< domain
->nconversions
; i
++)
1290 struct converted_domain
*convd
= &domain
->conversions
[i
];
1292 free ((char *) convd
->encoding
);
1293 if (convd
->conv_tab
!= NULL
&& convd
->conv_tab
!= (char **) -1)
1294 free (convd
->conv_tab
);
1295 if (convd
->conv
!= (__gconv_t
) -1)
1296 __gconv_close (convd
->conv
);
1298 free (domain
->conversions
);
1299 __libc_rwlock_fini (domain
->conversions_lock
);
1301 free (domain
->malloced
);
1303 # ifdef _POSIX_MAPPED_FILES
1304 if (domain
->use_mmap
)
1305 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1307 # endif /* _POSIX_MAPPED_FILES */
1308 free ((void *) domain
->data
);