diff options
Diffstat (limited to 'intl/loadmsgcat.c')
-rw-r--r-- | intl/loadmsgcat.c | 123 |
1 files changed, 81 insertions, 42 deletions
diff --git a/intl/loadmsgcat.c b/intl/loadmsgcat.c index 18bd501139..8eb77d8fe9 100644 --- a/intl/loadmsgcat.c +++ b/intl/loadmsgcat.c @@ -1,20 +1,18 @@ /* Load needed message catalogs. - Copyright (C) 1995-2014 Free Software Foundation, Inc. - This file is part of the GNU C Library. + Copyright (C) 1995-2015 Free Software Foundation, Inc. - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. - The GNU C Library is distributed in the hope that it will be useful, + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* Tell glibc's <string.h> to provide a prototype for mempcpy(). This must come before <config.h> because <config.h> may include @@ -39,14 +37,19 @@ # define alloca __builtin_alloca # define HAVE_ALLOCA 1 #else -# if defined HAVE_ALLOCA_H || defined _LIBC -# include <alloca.h> +# ifdef _MSC_VER +# include <malloc.h> +# define alloca _alloca # else -# ifdef _AIX - #pragma alloca +# if defined HAVE_ALLOCA_H || defined _LIBC +# include <alloca.h> # else -# ifndef alloca +# ifdef _AIX + #pragma alloca +# else +# ifndef alloca char *alloca (); +# endif # endif # endif # endif @@ -88,7 +91,17 @@ char *alloca (); #ifdef _LIBC # include "../locale/localeinfo.h" # include <not-cancel.h> +#endif + +/* Handle multi-threaded applications. */ +#ifdef _LIBC # include <bits/libc-lock.h> +#else +# include "lock.h" +#endif + +#ifdef _LIBC +# define PRI_MACROS_BROKEN 0 #endif /* Provide fallback values for macros that ought to be defined in <inttypes.h>. @@ -472,10 +485,22 @@ char *alloca (); # define freea(p) free (p) #endif - -/* Prototypes for local functions. Needed to ensure compiler checking of - function argument counts despite of K&R C function definition syntax. */ -static const char *get_sysdep_segment_value PARAMS ((const char *name)); +/* For systems that distinguish between text and binary I/O. + O_BINARY is usually declared in <fcntl.h>. */ +#if !defined O_BINARY && defined _O_BINARY + /* For MSC-compatible compilers. */ +# define O_BINARY _O_BINARY +# define O_TEXT _O_TEXT +#endif +#ifdef __BEOS__ + /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */ +# undef O_BINARY +# undef O_TEXT +#endif +/* On reasonable systems, binary I/O is the default. */ +#ifndef O_BINARY +# define O_BINARY 0 +#endif /* We need a sign, whether a new catalog was loaded, which can be associated @@ -486,8 +511,7 @@ int _nl_msg_cat_cntr; /* Expand a system dependent string segment. Return NULL if unsupported. */ static const char * -get_sysdep_segment_value (name) - const char *name; +get_sysdep_segment_value (const char *name) { /* Test for an ISO C 99 section 7.8.1 format string directive. Syntax: @@ -739,10 +763,12 @@ get_sysdep_segment_value (name) /* Test for a glibc specific printf() format directive flag. */ if (name[0] == 'I' && name[1] == '\0') { -#if defined _LIBC || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) +#if defined _LIBC \ + || ((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) \ + && !defined __UCLIBC__) /* The 'I' flag, in numeric format directives, replaces ASCII digits with the 'outdigits' defined in the LC_CTYPE locale facet. This is - used for Farsi (Persian) and maybe Arabic. */ + used for Farsi (Persian), some Indic languages, and maybe Arabic. */ return "I"; #else return ""; @@ -756,9 +782,8 @@ get_sysdep_segment_value (name) message catalog do nothing. */ void internal_function -_nl_load_domain (domain_file, domainbinding) - struct loaded_l10nfile *domain_file; - struct binding *domainbinding; +_nl_load_domain (struct loaded_l10nfile *domain_file, + struct binding *domainbinding) { __libc_lock_define_initialized_recursive (static, lock); int fd = -1; @@ -780,16 +805,14 @@ _nl_load_domain (domain_file, domainbinding) { /* There are two possibilities: - + is is the same thread calling again during this - initialization via _nl_find_msg. We have initialized - everything this call needs. + + this is the same thread calling again during this initialization + via _nl_find_msg. We have initialized everything this call needs. + this is another thread which tried to initialize this object. - Not necessary anymore since if the lock is available this + Not necessary anymore since if the lock is available this is finished. */ - __libc_lock_unlock_recursive (lock); - return; + goto done; } domain_file->decided = -1; @@ -807,7 +830,7 @@ _nl_load_domain (domain_file, domainbinding) goto out; /* Try to open the addressed file. */ - fd = open (domain_file->filename, O_RDONLY); + fd = open (domain_file->filename, O_RDONLY | O_BINARY); if (fd == -1) goto out; @@ -821,7 +844,7 @@ _nl_load_domain (domain_file, domainbinding) || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0) || __builtin_expect (size < sizeof (struct mo_file_header), 0)) /* Something went wrong. */ - goto out;; + goto out; #ifdef HAVE_MMAP /* Now we are ready to load the file. If mmap() is available we try @@ -855,11 +878,15 @@ _nl_load_domain (domain_file, domainbinding) read_ptr = (char *) data; do { - long int nb = (long int) TEMP_FAILURE_RETRY (read (fd, read_ptr, - to_read)); + long int nb = (long int) read (fd, read_ptr, to_read); if (nb <= 0) - goto out; - + { +#ifdef EINTR + if (nb == -1 && errno == EINTR) + continue; +#endif + goto out; + } read_ptr += nb; to_read -= nb; } @@ -956,6 +983,7 @@ _nl_load_domain (domain_file, domainbinding) ((char *) data + W (domain->must_swap, data->sysdep_segments_offset)); sysdep_segment_values = + (const char **) alloca (n_sysdep_segments * sizeof (const char *)); for (i = 0; i < n_sysdep_segments; i++) { @@ -1253,13 +1281,24 @@ _nl_load_domain (domain_file, domainbinding) /* No caches of converted translations so far. */ domain->conversions = NULL; domain->nconversions = 0; +#ifdef _LIBC __libc_rwlock_init (domain->conversions_lock); +#else + gl_rwlock_init (domain->conversions_lock); +#endif /* Get the header entry and look for a plural specification. */ +#ifdef IN_LIBGLOCALE + nullentry = + _nl_find_msg (domain_file, domainbinding, NULL, "", &nullentrylen); +#else nullentry = _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen); +#endif if (__builtin_expect (nullentry == (char *) -1, 0)) { +#ifdef _LIBC __libc_rwlock_fini (domain->conversions_lock); +#endif goto invalid; } EXTRACT_PLURAL_EXPRESSION (nullentry, &domain->plural, &domain->nplurals); @@ -1270,6 +1309,7 @@ _nl_load_domain (domain_file, domainbinding) domain_file->decided = 1; + done: __libc_lock_unlock_recursive (lock); } @@ -1277,8 +1317,7 @@ _nl_load_domain (domain_file, domainbinding) #ifdef _LIBC void internal_function __libc_freeres_fn_section -_nl_unload_domain (domain) - struct loaded_domain *domain; +_nl_unload_domain (struct loaded_domain *domain) { size_t i; |