457
465
/* Rename the non ISO C functions. This is required by the standard
458
466
because some ISO C functions will require linking with this object
459
467
file and the name space must not be polluted. */
461
# define close __close
464
# define munmap __munmap
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)
467
476
/* For those losing systems which don't have `alloca' we have to add
767
/* Initialize the codeset dependent parts of an opened message catalog.
768
Return the header entry. */
771
_nl_init_domain_conv (struct loaded_l10nfile *domain_file,
772
struct loaded_domain *domain,
773
struct binding *domainbinding)
775
/* Find out about the character set the file is encoded with.
776
This can be found (in textual form) in the entry "". If this
777
entry does not exist or if this does not contain the `charset='
778
information, we will assume the charset matches the one the
779
current locale and we don't have to perform any conversion. */
783
/* Preinitialize fields, to avoid recursion during _nl_find_msg. */
784
domain->codeset_cntr =
785
(domainbinding != NULL ? domainbinding->codeset_cntr : 0);
787
domain->conv = (__gconv_t) -1;
790
domain->conv = (iconv_t) -1;
793
domain->conv_tab = NULL;
795
/* Get the header entry. */
796
nullentry = _nl_find_msg (domain_file, domainbinding, "", &nullentrylen);
798
if (nullentry != NULL)
800
#if defined _LIBC || HAVE_ICONV
801
const char *charsetstr;
803
charsetstr = strstr (nullentry, "charset=");
804
if (charsetstr != NULL)
808
const char *outcharset;
810
charsetstr += strlen ("charset=");
811
len = strcspn (charsetstr, " \t\n");
813
charset = (char *) alloca (len + 1);
814
# if defined _LIBC || HAVE_MEMPCPY
815
*((char *) mempcpy (charset, charsetstr, len)) = '\0';
817
memcpy (charset, charsetstr, len);
821
/* The output charset should normally be determined by the
822
locale. But sometimes the locale is not used or not correctly
823
set up, so we provide a possibility for the user to override
824
this. Moreover, the value specified through
825
bind_textdomain_codeset overrides both. */
826
if (domainbinding != NULL && domainbinding->codeset != NULL)
827
outcharset = domainbinding->codeset;
830
outcharset = getenv ("OUTPUT_CHARSET");
831
if (outcharset == NULL || outcharset[0] == '\0')
834
outcharset = _NL_CURRENT (LC_CTYPE, CODESET);
837
extern const char *locale_charset (void);
838
outcharset = locale_charset ();
845
/* We always want to use transliteration. */
846
outcharset = norm_add_slashes (outcharset, "TRANSLIT");
847
charset = norm_add_slashes (charset, NULL);
848
if (__gconv_open (outcharset, charset, &domain->conv,
851
domain->conv = (__gconv_t) -1;
854
/* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,
855
we want to use transliteration. */
856
# if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \
857
|| _LIBICONV_VERSION >= 0x0105
858
if (strchr (outcharset, '/') == NULL)
862
len = strlen (outcharset);
863
tmp = (char *) alloca (len + 10 + 1);
864
memcpy (tmp, outcharset, len);
865
memcpy (tmp + len, "//TRANSLIT", 10 + 1);
868
domain->conv = iconv_open (outcharset, charset);
874
domain->conv = iconv_open (outcharset, charset);
880
#endif /* _LIBC || HAVE_ICONV */
886
/* Frees the codeset dependent parts of an opened message catalog. */
889
_nl_free_domain_conv (struct loaded_domain *domain)
891
if (domain->conv_tab != NULL && domain->conv_tab != (char **) -1)
892
free (domain->conv_tab);
895
if (domain->conv != (__gconv_t) -1)
896
__gconv_close (domain->conv);
899
if (domain->conv != (iconv_t) -1)
900
iconv_close (domain->conv);
905
776
/* Load the message catalogs specified by FILENAME. If it is no valid
906
777
message catalog do nothing. */
921
793
struct loaded_domain *domain;
923
795
const char *nullentry;
925
domain_file->decided = 1;
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;
926
814
domain_file->data = NULL;
928
816
/* Note that it would be useless to store domainbinding in domain_file
1384
1270
domain_file->data = NULL;
1388
/* Now initialize the character set converter from the character set
1389
the file is encoded with (found in the header entry) to the domain's
1390
specified character set or the locale's character set. */
1391
nullentry = _nl_init_domain_conv (domain_file, domain, domainbinding);
1274
/* No caches of converted translations so far. */
1275
domain->conversions = NULL;
1276
domain->nconversions = 0;
1393
/* Also look for a plural specification. */
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);
1394
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
1401
1301
_nl_unload_domain (struct loaded_domain *domain)
1403
1305
if (domain->plural != &__gettext_germanic_plural)
1404
1306
__gettext_free_exp (domain->plural);
1406
_nl_free_domain_conv (domain);
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);
1408
1321
if (domain->malloced)
1409
1322
free (domain->malloced);