1 /* Load needed message catalogs.
2 Copyright (C) 1995-2023 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
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
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Tell glibc's <string.h> to provide a prototype for mempcpy().
18 This must come before <config.h> because <config.h> may include
19 <features.h>, and once <features.h> has been included, it's too late. */
21 # define _GNU_SOURCE 1
32 #include <sys/types.h>
38 #if defined HAVE_UNISTD_H || defined _LIBC
43 # include <langinfo.h>
47 #if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
48 || (defined _LIBC && defined _POSIX_MAPPED_FILES)
49 # include <sys/mman.h>
56 #if defined HAVE_STDINT_H_WITH_UINTMAX || defined _LIBC
59 #if defined HAVE_INTTYPES_H || defined _LIBC
60 # include <inttypes.h>
65 #include "hash-string.h"
66 #include "plural-exp.h"
69 # include "../locale/localeinfo.h"
70 # include <not-cancel.h>
73 /* Handle multi-threaded applications. */
75 # include <libc-lock.h>
81 # define PRI_MACROS_BROKEN 0
84 /* Provide fallback values for macros that ought to be defined in <inttypes.h>.
85 Note that our fallback values need not be literal strings, because we don't
86 use them with preprocessor string concatenation. */
87 #if !defined PRId8 || PRI_MACROS_BROKEN
91 #if !defined PRIi8 || PRI_MACROS_BROKEN
95 #if !defined PRIo8 || PRI_MACROS_BROKEN
99 #if !defined PRIu8 || PRI_MACROS_BROKEN
103 #if !defined PRIx8 || PRI_MACROS_BROKEN
107 #if !defined PRIX8 || PRI_MACROS_BROKEN
111 #if !defined PRId16 || PRI_MACROS_BROKEN
115 #if !defined PRIi16 || PRI_MACROS_BROKEN
119 #if !defined PRIo16 || PRI_MACROS_BROKEN
123 #if !defined PRIu16 || PRI_MACROS_BROKEN
127 #if !defined PRIx16 || PRI_MACROS_BROKEN
131 #if !defined PRIX16 || PRI_MACROS_BROKEN
135 #if !defined PRId32 || PRI_MACROS_BROKEN
139 #if !defined PRIi32 || PRI_MACROS_BROKEN
143 #if !defined PRIo32 || PRI_MACROS_BROKEN
147 #if !defined PRIu32 || PRI_MACROS_BROKEN
151 #if !defined PRIx32 || PRI_MACROS_BROKEN
155 #if !defined PRIX32 || PRI_MACROS_BROKEN
159 #if !defined PRId64 || PRI_MACROS_BROKEN
161 # define PRId64 (sizeof (long) == 8 ? "ld" : "lld")
163 #if !defined PRIi64 || PRI_MACROS_BROKEN
165 # define PRIi64 (sizeof (long) == 8 ? "li" : "lli")
167 #if !defined PRIo64 || PRI_MACROS_BROKEN
169 # define PRIo64 (sizeof (long) == 8 ? "lo" : "llo")
171 #if !defined PRIu64 || PRI_MACROS_BROKEN
173 # define PRIu64 (sizeof (long) == 8 ? "lu" : "llu")
175 #if !defined PRIx64 || PRI_MACROS_BROKEN
177 # define PRIx64 (sizeof (long) == 8 ? "lx" : "llx")
179 #if !defined PRIX64 || PRI_MACROS_BROKEN
181 # define PRIX64 (sizeof (long) == 8 ? "lX" : "llX")
183 #if !defined PRIdLEAST8 || PRI_MACROS_BROKEN
185 # define PRIdLEAST8 "d"
187 #if !defined PRIiLEAST8 || PRI_MACROS_BROKEN
189 # define PRIiLEAST8 "i"
191 #if !defined PRIoLEAST8 || PRI_MACROS_BROKEN
193 # define PRIoLEAST8 "o"
195 #if !defined PRIuLEAST8 || PRI_MACROS_BROKEN
197 # define PRIuLEAST8 "u"
199 #if !defined PRIxLEAST8 || PRI_MACROS_BROKEN
201 # define PRIxLEAST8 "x"
203 #if !defined PRIXLEAST8 || PRI_MACROS_BROKEN
205 # define PRIXLEAST8 "X"
207 #if !defined PRIdLEAST16 || PRI_MACROS_BROKEN
209 # define PRIdLEAST16 "d"
211 #if !defined PRIiLEAST16 || PRI_MACROS_BROKEN
213 # define PRIiLEAST16 "i"
215 #if !defined PRIoLEAST16 || PRI_MACROS_BROKEN
217 # define PRIoLEAST16 "o"
219 #if !defined PRIuLEAST16 || PRI_MACROS_BROKEN
221 # define PRIuLEAST16 "u"
223 #if !defined PRIxLEAST16 || PRI_MACROS_BROKEN
225 # define PRIxLEAST16 "x"
227 #if !defined PRIXLEAST16 || PRI_MACROS_BROKEN
229 # define PRIXLEAST16 "X"
231 #if !defined PRIdLEAST32 || PRI_MACROS_BROKEN
233 # define PRIdLEAST32 "d"
235 #if !defined PRIiLEAST32 || PRI_MACROS_BROKEN
237 # define PRIiLEAST32 "i"
239 #if !defined PRIoLEAST32 || PRI_MACROS_BROKEN
241 # define PRIoLEAST32 "o"
243 #if !defined PRIuLEAST32 || PRI_MACROS_BROKEN
245 # define PRIuLEAST32 "u"
247 #if !defined PRIxLEAST32 || PRI_MACROS_BROKEN
249 # define PRIxLEAST32 "x"
251 #if !defined PRIXLEAST32 || PRI_MACROS_BROKEN
253 # define PRIXLEAST32 "X"
255 #if !defined PRIdLEAST64 || PRI_MACROS_BROKEN
257 # define PRIdLEAST64 PRId64
259 #if !defined PRIiLEAST64 || PRI_MACROS_BROKEN
261 # define PRIiLEAST64 PRIi64
263 #if !defined PRIoLEAST64 || PRI_MACROS_BROKEN
265 # define PRIoLEAST64 PRIo64
267 #if !defined PRIuLEAST64 || PRI_MACROS_BROKEN
269 # define PRIuLEAST64 PRIu64
271 #if !defined PRIxLEAST64 || PRI_MACROS_BROKEN
273 # define PRIxLEAST64 PRIx64
275 #if !defined PRIXLEAST64 || PRI_MACROS_BROKEN
277 # define PRIXLEAST64 PRIX64
279 #if !defined PRIdFAST8 || PRI_MACROS_BROKEN
281 # define PRIdFAST8 "d"
283 #if !defined PRIiFAST8 || PRI_MACROS_BROKEN
285 # define PRIiFAST8 "i"
287 #if !defined PRIoFAST8 || PRI_MACROS_BROKEN
289 # define PRIoFAST8 "o"
291 #if !defined PRIuFAST8 || PRI_MACROS_BROKEN
293 # define PRIuFAST8 "u"
295 #if !defined PRIxFAST8 || PRI_MACROS_BROKEN
297 # define PRIxFAST8 "x"
299 #if !defined PRIXFAST8 || PRI_MACROS_BROKEN
301 # define PRIXFAST8 "X"
303 #if !defined PRIdFAST16 || PRI_MACROS_BROKEN
305 # define PRIdFAST16 "d"
307 #if !defined PRIiFAST16 || PRI_MACROS_BROKEN
309 # define PRIiFAST16 "i"
311 #if !defined PRIoFAST16 || PRI_MACROS_BROKEN
313 # define PRIoFAST16 "o"
315 #if !defined PRIuFAST16 || PRI_MACROS_BROKEN
317 # define PRIuFAST16 "u"
319 #if !defined PRIxFAST16 || PRI_MACROS_BROKEN
321 # define PRIxFAST16 "x"
323 #if !defined PRIXFAST16 || PRI_MACROS_BROKEN
325 # define PRIXFAST16 "X"
327 #if !defined PRIdFAST32 || PRI_MACROS_BROKEN
329 # define PRIdFAST32 "d"
331 #if !defined PRIiFAST32 || PRI_MACROS_BROKEN
333 # define PRIiFAST32 "i"
335 #if !defined PRIoFAST32 || PRI_MACROS_BROKEN
337 # define PRIoFAST32 "o"
339 #if !defined PRIuFAST32 || PRI_MACROS_BROKEN
341 # define PRIuFAST32 "u"
343 #if !defined PRIxFAST32 || PRI_MACROS_BROKEN
345 # define PRIxFAST32 "x"
347 #if !defined PRIXFAST32 || PRI_MACROS_BROKEN
349 # define PRIXFAST32 "X"
351 #if !defined PRIdFAST64 || PRI_MACROS_BROKEN
353 # define PRIdFAST64 PRId64
355 #if !defined PRIiFAST64 || PRI_MACROS_BROKEN
357 # define PRIiFAST64 PRIi64
359 #if !defined PRIoFAST64 || PRI_MACROS_BROKEN
361 # define PRIoFAST64 PRIo64
363 #if !defined PRIuFAST64 || PRI_MACROS_BROKEN
365 # define PRIuFAST64 PRIu64
367 #if !defined PRIxFAST64 || PRI_MACROS_BROKEN
369 # define PRIxFAST64 PRIx64
371 #if !defined PRIXFAST64 || PRI_MACROS_BROKEN
373 # define PRIXFAST64 PRIX64
375 #if !defined PRIdMAX || PRI_MACROS_BROKEN
377 # define PRIdMAX (sizeof (uintmax_t) == sizeof (long) ? "ld" : "lld")
379 #if !defined PRIiMAX || PRI_MACROS_BROKEN
381 # define PRIiMAX (sizeof (uintmax_t) == sizeof (long) ? "li" : "lli")
383 #if !defined PRIoMAX || PRI_MACROS_BROKEN
385 # define PRIoMAX (sizeof (uintmax_t) == sizeof (long) ? "lo" : "llo")
387 #if !defined PRIuMAX || PRI_MACROS_BROKEN
389 # define PRIuMAX (sizeof (uintmax_t) == sizeof (long) ? "lu" : "llu")
391 #if !defined PRIxMAX || PRI_MACROS_BROKEN
393 # define PRIxMAX (sizeof (uintmax_t) == sizeof (long) ? "lx" : "llx")
395 #if !defined PRIXMAX || PRI_MACROS_BROKEN
397 # define PRIXMAX (sizeof (uintmax_t) == sizeof (long) ? "lX" : "llX")
399 #if !defined PRIdPTR || PRI_MACROS_BROKEN
402 (sizeof (void *) == sizeof (long) ? "ld" : \
403 sizeof (void *) == sizeof (int) ? "d" : \
406 #if !defined PRIiPTR || PRI_MACROS_BROKEN
409 (sizeof (void *) == sizeof (long) ? "li" : \
410 sizeof (void *) == sizeof (int) ? "i" : \
413 #if !defined PRIoPTR || PRI_MACROS_BROKEN
416 (sizeof (void *) == sizeof (long) ? "lo" : \
417 sizeof (void *) == sizeof (int) ? "o" : \
420 #if !defined PRIuPTR || PRI_MACROS_BROKEN
423 (sizeof (void *) == sizeof (long) ? "lu" : \
424 sizeof (void *) == sizeof (int) ? "u" : \
427 #if !defined PRIxPTR || PRI_MACROS_BROKEN
430 (sizeof (void *) == sizeof (long) ? "lx" : \
431 sizeof (void *) == sizeof (int) ? "x" : \
434 #if !defined PRIXPTR || PRI_MACROS_BROKEN
437 (sizeof (void *) == sizeof (long) ? "lX" : \
438 sizeof (void *) == sizeof (int) ? "X" : \
442 /* @@ end of prolog @@ */
445 /* Rename the non ISO C functions. This is required by the standard
446 because some ISO C functions will require linking with this object
447 file and the name space must not be polluted. */
448 # define open(name, flags) __open_nocancel (name, flags)
449 # define close(fd) __close_nocancel_nostatus (fd)
450 # define read(fd, buf, n) __read_nocancel (fd, buf, n)
451 # define mmap(addr, len, prot, flags, fd, offset) \
452 __mmap (addr, len, prot, flags, fd, offset)
453 # define munmap(addr, len) __munmap (addr, len)
456 /* For systems that distinguish between text and binary I/O.
457 O_BINARY is usually declared in <fcntl.h>. */
458 #if !defined O_BINARY && defined _O_BINARY
459 /* For MSC-compatible compilers. */
460 # define O_BINARY _O_BINARY
461 # define O_TEXT _O_TEXT
464 /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
468 /* On reasonable systems, binary I/O is the default. */
474 /* We need a sign, whether a new catalog was loaded, which can be associated
475 with all translations. This is important if the translations are
476 cached by one of GCC's features. */
477 int _nl_msg_cat_cntr
;
480 /* Expand a system dependent string segment. Return NULL if unsupported. */
482 get_sysdep_segment_value (const char *name
)
484 /* Test for an ISO C 99 section 7.8.1 format string directive.
486 P R I { d | i | o | u | x | X }
487 { { | LEAST | FAST } { 8 | 16 | 32 | 64 } | MAX | PTR } */
488 /* We don't use a table of 14 times 6 'const char *' strings here, because
489 data relocations cost startup time. */
490 if (name
[0] == 'P' && name
[1] == 'R' && name
[2] == 'I')
492 if (name
[3] == 'd' || name
[3] == 'i' || name
[3] == 'o' || name
[3] == 'u'
493 || name
[3] == 'x' || name
[3] == 'X')
495 if (name
[4] == '8' && name
[5] == '\0')
511 if (name
[4] == '1' && name
[5] == '6' && name
[6] == '\0')
527 if (name
[4] == '3' && name
[5] == '2' && name
[6] == '\0')
543 if (name
[4] == '6' && name
[5] == '4' && name
[6] == '\0')
559 if (name
[4] == 'L' && name
[5] == 'E' && name
[6] == 'A'
560 && name
[7] == 'S' && name
[8] == 'T')
562 if (name
[9] == '8' && name
[10] == '\0')
578 if (name
[9] == '1' && name
[10] == '6' && name
[11] == '\0')
594 if (name
[9] == '3' && name
[10] == '2' && name
[11] == '\0')
610 if (name
[9] == '6' && name
[10] == '4' && name
[11] == '\0')
627 if (name
[4] == 'F' && name
[5] == 'A' && name
[6] == 'S'
630 if (name
[8] == '8' && name
[9] == '\0')
646 if (name
[8] == '1' && name
[9] == '6' && name
[10] == '\0')
662 if (name
[8] == '3' && name
[9] == '2' && name
[10] == '\0')
678 if (name
[8] == '6' && name
[9] == '4' && name
[10] == '\0')
695 if (name
[4] == 'M' && name
[5] == 'A' && name
[6] == 'X'
712 if (name
[4] == 'P' && name
[5] == 'T' && name
[6] == 'R'
731 /* Test for a glibc specific printf() format directive flag. */
732 if (name
[0] == 'I' && name
[1] == '\0')
735 || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) \
736 && !defined __UCLIBC__)
737 /* The 'I' flag, in numeric format directives, replaces ASCII digits
738 with the 'outdigits' defined in the LC_CTYPE locale facet. This is
739 used for Farsi (Persian), some Indic languages, and maybe Arabic. */
745 /* Other system dependent strings are not valid. */
749 /* Load the message catalogs specified by FILENAME. If it is no valid
750 message catalog do nothing. */
752 _nl_load_domain (struct loaded_l10nfile
*domain_file
,
753 struct binding
*domainbinding
)
755 __libc_lock_define_initialized_recursive (static, lock
);
759 struct __stat64_t64 st
;
763 struct mo_file_header
*data
= (struct mo_file_header
*) -1;
765 struct loaded_domain
*domain
;
767 const char *nullentry
;
770 __libc_lock_lock_recursive (lock
);
771 if (domain_file
->decided
!= 0)
773 /* There are two possibilities:
775 + this is the same thread calling again during this initialization
776 via _nl_find_msg. We have initialized everything this call needs.
778 + this is another thread which tried to initialize this object.
779 Not necessary anymore since if the lock is available this
785 domain_file
->decided
= -1;
786 domain_file
->data
= NULL
;
788 /* Note that it would be useless to store domainbinding in domain_file
789 because domainbinding might be == NULL now but != NULL later (after
790 a call to bind_textdomain_codeset). */
792 /* If the record does not represent a valid locale the FILENAME
793 might be NULL. This can happen when according to the given
794 specification the locale file name is different for XPG and CEN
796 if (domain_file
->filename
== NULL
)
799 /* Try to open the addressed file. */
800 fd
= open (domain_file
->filename
, O_RDONLY
| O_BINARY
);
804 /* We must know about the size of the file. */
807 __glibc_unlikely (__fstat64_time64 (fd
, &st
) != 0)
809 __builtin_expect (fstat (fd
, &st
) != 0, 0)
811 || __builtin_expect ((size
= (size_t) st
.st_size
) != st
.st_size
, 0)
812 || __builtin_expect (size
< sizeof (struct mo_file_header
), 0))
813 /* Something went wrong. */
817 /* Now we are ready to load the file. If mmap() is available we try
818 this first. If not available or it failed we try to load it. */
819 data
= (struct mo_file_header
*) mmap (NULL
, size
, PROT_READ
,
822 if (__builtin_expect (data
!= MAP_FAILED
, 1))
824 /* mmap() call was successful. */
830 assert (MAP_FAILED
== (void *) -1);
833 /* If the data is not yet available (i.e. mmap'ed) we try to load
835 if (data
== (struct mo_file_header
*) -1)
840 data
= (struct mo_file_header
*) malloc (size
);
845 read_ptr
= (char *) data
;
848 long int nb
= (long int) read (fd
, read_ptr
, to_read
);
852 if (nb
== -1 && errno
== EINTR
)
866 /* Using the magic number we can test whether it really is a message
868 if (__builtin_expect (data
->magic
!= _MAGIC
&& data
->magic
!= _MAGIC_SWAPPED
,
871 /* The magic number is wrong: not a message catalog file. */
874 munmap ((caddr_t
) data
, size
);
881 domain
= (struct loaded_domain
*) malloc (sizeof (struct loaded_domain
));
884 domain_file
->data
= domain
;
886 domain
->data
= (char *) data
;
887 domain
->use_mmap
= use_mmap
;
888 domain
->mmap_size
= size
;
889 domain
->must_swap
= data
->magic
!= _MAGIC
;
890 domain
->malloced
= NULL
;
892 /* Fill in the information about the available tables. */
893 revision
= W (domain
->must_swap
, data
->revision
);
894 /* We support only the major revisions 0 and 1. */
895 switch (revision
>> 16)
899 domain
->nstrings
= W (domain
->must_swap
, data
->nstrings
);
900 domain
->orig_tab
= (const struct string_desc
*)
901 ((char *) data
+ W (domain
->must_swap
, data
->orig_tab_offset
));
902 domain
->trans_tab
= (const struct string_desc
*)
903 ((char *) data
+ W (domain
->must_swap
, data
->trans_tab_offset
));
904 domain
->hash_size
= W (domain
->must_swap
, data
->hash_tab_size
);
906 (domain
->hash_size
> 2
907 ? (const nls_uint32
*)
908 ((char *) data
+ W (domain
->must_swap
, data
->hash_tab_offset
))
910 domain
->must_swap_hash_tab
= domain
->must_swap
;
912 /* Now dispatch on the minor revision. */
913 switch (revision
& 0xffff)
916 domain
->n_sysdep_strings
= 0;
917 domain
->orig_sysdep_tab
= NULL
;
918 domain
->trans_sysdep_tab
= NULL
;
923 nls_uint32 n_sysdep_strings
;
925 if (domain
->hash_tab
== NULL
)
926 /* This is invalid. These minor revisions need a hash table. */
930 W (domain
->must_swap
, data
->n_sysdep_strings
);
931 if (n_sysdep_strings
> 0)
933 nls_uint32 n_sysdep_segments
;
934 const struct sysdep_segment
*sysdep_segments
;
935 const char **sysdep_segment_values
;
936 const nls_uint32
*orig_sysdep_tab
;
937 const nls_uint32
*trans_sysdep_tab
;
938 nls_uint32 n_inmem_sysdep_strings
;
941 struct sysdep_string_desc
*inmem_orig_sysdep_tab
;
942 struct sysdep_string_desc
*inmem_trans_sysdep_tab
;
943 nls_uint32
*inmem_hash_tab
;
946 /* Get the values of the system dependent segments. */
948 W (domain
->must_swap
, data
->n_sysdep_segments
);
949 sysdep_segments
= (const struct sysdep_segment
*)
951 + W (domain
->must_swap
, data
->sysdep_segments_offset
));
952 sysdep_segment_values
= calloc
953 (n_sysdep_segments
, sizeof (const char *));
954 if (sysdep_segment_values
== NULL
)
956 for (i
= 0; i
< n_sysdep_segments
; i
++)
960 + W (domain
->must_swap
, sysdep_segments
[i
].offset
);
962 W (domain
->must_swap
, sysdep_segments
[i
].length
);
964 if (!(namelen
> 0 && name
[namelen
- 1] == '\0'))
966 free (sysdep_segment_values
);
970 sysdep_segment_values
[i
] = get_sysdep_segment_value (name
);
973 orig_sysdep_tab
= (const nls_uint32
*)
975 + W (domain
->must_swap
, data
->orig_sysdep_tab_offset
));
976 trans_sysdep_tab
= (const nls_uint32
*)
978 + W (domain
->must_swap
, data
->trans_sysdep_tab_offset
));
980 /* Compute the amount of additional memory needed for the
981 system dependent strings and the augmented hash table.
982 At the same time, also drop string pairs which refer to
983 an undefined system dependent segment. */
984 n_inmem_sysdep_strings
= 0;
985 memneed
= domain
->hash_size
* sizeof (nls_uint32
);
986 for (i
= 0; i
< n_sysdep_strings
; i
++)
991 for (j
= 0; j
< 2; j
++)
993 const struct sysdep_string
*sysdep_string
=
994 (const struct sysdep_string
*)
996 + W (domain
->must_swap
,
999 : trans_sysdep_tab
[i
]));
1001 const struct segment_pair
*p
= sysdep_string
->segments
;
1003 if (W (domain
->must_swap
, p
->sysdepref
) != SEGMENTS_END
)
1004 for (p
= sysdep_string
->segments
;; p
++)
1006 nls_uint32 sysdepref
;
1008 need
+= W (domain
->must_swap
, p
->segsize
);
1010 sysdepref
= W (domain
->must_swap
, p
->sysdepref
);
1011 if (sysdepref
== SEGMENTS_END
)
1014 if (sysdepref
>= n_sysdep_segments
)
1017 free (sysdep_segment_values
);
1021 if (sysdep_segment_values
[sysdepref
] == NULL
)
1023 /* This particular string pair is invalid. */
1028 need
+= strlen (sysdep_segment_values
[sysdepref
]);
1038 n_inmem_sysdep_strings
++;
1039 memneed
+= needs
[0] + needs
[1];
1042 memneed
+= 2 * n_inmem_sysdep_strings
1043 * sizeof (struct sysdep_string_desc
);
1045 if (n_inmem_sysdep_strings
> 0)
1049 /* Allocate additional memory. */
1050 mem
= (char *) malloc (memneed
);
1054 domain
->malloced
= mem
;
1055 inmem_orig_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1056 mem
+= n_inmem_sysdep_strings
1057 * sizeof (struct sysdep_string_desc
);
1058 inmem_trans_sysdep_tab
= (struct sysdep_string_desc
*) mem
;
1059 mem
+= n_inmem_sysdep_strings
1060 * sizeof (struct sysdep_string_desc
);
1061 inmem_hash_tab
= (nls_uint32
*) mem
;
1062 mem
+= domain
->hash_size
* sizeof (nls_uint32
);
1064 /* Compute the system dependent strings. */
1066 for (i
= 0; i
< n_sysdep_strings
; i
++)
1070 for (j
= 0; j
< 2; j
++)
1072 const struct sysdep_string
*sysdep_string
=
1073 (const struct sysdep_string
*)
1075 + W (domain
->must_swap
,
1077 ? orig_sysdep_tab
[i
]
1078 : trans_sysdep_tab
[i
]));
1079 const struct segment_pair
*p
=
1080 sysdep_string
->segments
;
1082 if (W (domain
->must_swap
, p
->sysdepref
)
1084 for (p
= sysdep_string
->segments
;; p
++)
1086 nls_uint32 sysdepref
;
1089 W (domain
->must_swap
, p
->sysdepref
);
1090 if (sysdepref
== SEGMENTS_END
)
1093 if (sysdep_segment_values
[sysdepref
] == NULL
)
1095 /* This particular string pair is
1108 for (j
= 0; j
< 2; j
++)
1110 const struct sysdep_string
*sysdep_string
=
1111 (const struct sysdep_string
*)
1113 + W (domain
->must_swap
,
1115 ? orig_sysdep_tab
[i
]
1116 : trans_sysdep_tab
[i
]));
1117 const char *static_segments
=
1119 + W (domain
->must_swap
, sysdep_string
->offset
);
1120 const struct segment_pair
*p
=
1121 sysdep_string
->segments
;
1123 /* Concatenate the segments, and fill
1124 inmem_orig_sysdep_tab[k] (for j == 0) and
1125 inmem_trans_sysdep_tab[k] (for j == 1). */
1127 struct sysdep_string_desc
*inmem_tab_entry
=
1129 ? inmem_orig_sysdep_tab
1130 : inmem_trans_sysdep_tab
)
1133 if (W (domain
->must_swap
, p
->sysdepref
)
1136 /* Only one static segment. */
1137 inmem_tab_entry
->length
=
1138 W (domain
->must_swap
, p
->segsize
);
1139 inmem_tab_entry
->pointer
= static_segments
;
1143 inmem_tab_entry
->pointer
= mem
;
1145 for (p
= sysdep_string
->segments
;; p
++)
1147 nls_uint32 segsize
=
1148 W (domain
->must_swap
, p
->segsize
);
1149 nls_uint32 sysdepref
=
1150 W (domain
->must_swap
, p
->sysdepref
);
1155 memcpy (mem
, static_segments
, segsize
);
1157 static_segments
+= segsize
;
1160 if (sysdepref
== SEGMENTS_END
)
1163 n
= strlen (sysdep_segment_values
[sysdepref
]);
1164 memcpy (mem
, sysdep_segment_values
[sysdepref
], n
);
1168 inmem_tab_entry
->length
=
1169 mem
- inmem_tab_entry
->pointer
;
1176 if (k
!= n_inmem_sysdep_strings
)
1179 /* Compute the augmented hash table. */
1180 for (i
= 0; i
< domain
->hash_size
; i
++)
1182 W (domain
->must_swap_hash_tab
, domain
->hash_tab
[i
]);
1183 for (i
= 0; i
< n_inmem_sysdep_strings
; i
++)
1185 const char *msgid
= inmem_orig_sysdep_tab
[i
].pointer
;
1186 nls_uint32 hash_val
= __hash_string (msgid
);
1187 nls_uint32 idx
= hash_val
% domain
->hash_size
;
1189 1 + (hash_val
% (domain
->hash_size
- 2));
1193 if (inmem_hash_tab
[idx
] == 0)
1195 /* Hash table entry is empty. Use it. */
1196 inmem_hash_tab
[idx
] = 1 + domain
->nstrings
+ i
;
1200 if (idx
>= domain
->hash_size
- incr
)
1201 idx
-= domain
->hash_size
- incr
;
1207 domain
->n_sysdep_strings
= n_inmem_sysdep_strings
;
1208 domain
->orig_sysdep_tab
= inmem_orig_sysdep_tab
;
1209 domain
->trans_sysdep_tab
= inmem_trans_sysdep_tab
;
1211 domain
->hash_tab
= inmem_hash_tab
;
1212 domain
->must_swap_hash_tab
= 0;
1216 domain
->n_sysdep_strings
= 0;
1217 domain
->orig_sysdep_tab
= NULL
;
1218 domain
->trans_sysdep_tab
= NULL
;
1221 free (sysdep_segment_values
);
1225 domain
->n_sysdep_strings
= 0;
1226 domain
->orig_sysdep_tab
= NULL
;
1227 domain
->trans_sysdep_tab
= NULL
;
1234 /* This is an invalid revision. */
1236 /* This is an invalid .mo file or we ran out of resources. */
1237 free (domain
->malloced
);
1240 munmap ((caddr_t
) data
, size
);
1245 domain_file
->data
= NULL
;
1249 /* No caches of converted translations so far. */
1250 domain
->conversions
= NULL
;
1251 domain
->nconversions
= 0;
1253 __libc_rwlock_init (domain
->conversions_lock
);
1255 gl_rwlock_init (domain
->conversions_lock
);
1258 /* Get the header entry and look for a plural specification. */
1259 #ifdef IN_LIBGLOCALE
1261 _nl_find_msg (domain_file
, domainbinding
, NULL
, "", &nullentrylen
);
1263 nullentry
= _nl_find_msg (domain_file
, domainbinding
, "", 0, &nullentrylen
);
1265 if (__builtin_expect (nullentry
== (char *) -1, 0))
1268 __libc_rwlock_fini (domain
->conversions_lock
);
1272 EXTRACT_PLURAL_EXPRESSION (nullentry
, &domain
->plural
, &domain
->nplurals
);
1278 domain_file
->decided
= 1;
1281 __libc_lock_unlock_recursive (lock
);
1287 __libc_freeres_fn_section
1288 _nl_unload_domain (struct loaded_domain
*domain
)
1292 if (domain
->plural
!= &__gettext_germanic_plural
)
1293 __gettext_free_exp ((struct expression
*) domain
->plural
);
1295 for (i
= 0; i
< domain
->nconversions
; i
++)
1297 struct converted_domain
*convd
= &domain
->conversions
[i
];
1299 free ((char *) convd
->encoding
);
1300 if (convd
->conv_tab
!= NULL
&& convd
->conv_tab
!= (char **) -1)
1301 free (convd
->conv_tab
);
1302 if (convd
->conv
!= (__gconv_t
) -1)
1303 __gconv_close (convd
->conv
);
1305 free (domain
->conversions
);
1306 __libc_rwlock_fini (domain
->conversions_lock
);
1308 free (domain
->malloced
);
1310 # ifdef _POSIX_MAPPED_FILES
1311 if (domain
->use_mmap
)
1312 munmap ((caddr_t
) domain
->data
, domain
->mmap_size
);
1314 # endif /* _POSIX_MAPPED_FILES */
1315 free ((void *) domain
->data
);