1 /* Implementation of the internal dcigettext function.
2 Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library 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 the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
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
30 #include <sys/types.h>
32 #if defined __GNUC__ && !defined C_ALLOCA
33 # define alloca __builtin_alloca
34 # define HAVE_ALLOCA 1
36 # if (defined HAVE_ALLOCA_H || defined _LIBC) && !defined C_ALLOCA
54 # define __set_errno(val) errno = (val)
57 #if defined STDC_HEADERS || defined _LIBC
68 #if defined HAVE_STRING_H || defined _LIBC
73 #if !HAVE_STRCHR && !defined _LIBC
79 #if defined HAVE_UNISTD_H || defined _LIBC
83 #if defined HAVE_LOCALE_H || defined _LIBC
87 #if defined HAVE_SYS_PARAM_H || defined _LIBC
88 # include <sys/param.h>
96 # include "libgettext.h"
98 #include "hash-string.h"
100 /* Thread safetyness. */
102 # include <bits/libc-lock.h>
104 /* Provide dummy implementation if this is outside glibc. */
105 # define __libc_lock_define_initialized(CLASS, NAME)
106 # define __libc_lock_lock(NAME)
107 # define __libc_lock_unlock(NAME)
108 # define __libc_rwlock_define_initialized(CLASS, NAME)
109 # define __libc_rwlock_rdlock(NAME)
110 # define __libc_rwlock_unlock(NAME)
113 /* Alignment of types. */
114 #if defined __GNUC__ && __GNUC__ >= 2
115 # define alignof(TYPE) __alignof__ (TYPE)
117 # define alignof(TYPE) \
118 ((int) &((struct { char dummy1; TYPE dummy2; } *) 0)->dummy2)
121 /* @@ end of prolog @@ */
124 /* Rename the non ANSI C functions. This is required by the standard
125 because some ANSI C functions will require linking with this object
126 file and the name space must not be polluted. */
127 # define getcwd __getcwd
129 # define stpcpy __stpcpy
132 # if !defined HAVE_GETCWD
134 # define getcwd(buf, max) getwd (buf)
139 static char *stpcpy
PARAMS ((char *dest
, const char *src
));
141 # ifndef HAVE_MEMPCPY
142 static void *mempcpy
PARAMS ((void *dest
, const void *src
, size_t n
));
146 /* Amount to increase buffer size by in each try. */
149 /* The following is from pathmax.h. */
150 /* Non-POSIX BSD systems might have gcc's limits.h, which doesn't define
151 PATH_MAX but might cause redefinition warnings when sys/param.h is
152 later included (as on MORE/BSD 4.3). */
153 #if defined _POSIX_VERSION || (defined HAVE_LIMITS_H && !defined __GNUC__)
157 #ifndef _POSIX_PATH_MAX
158 # define _POSIX_PATH_MAX 255
161 #if !defined PATH_MAX && defined _PC_PATH_MAX
162 # define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 : pathconf ("/", _PC_PATH_MAX))
165 /* Don't include sys/param.h if it already has been. */
166 #if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
167 # include <sys/param.h>
170 #if !defined PATH_MAX && defined MAXPATHLEN
171 # define PATH_MAX MAXPATHLEN
175 # define PATH_MAX _POSIX_PATH_MAX
178 /* XPG3 defines the result of `setlocale (category, NULL)' as:
179 ``Directs `setlocale()' to query `category' and return the current
180 setting of `local'.''
181 However it does not specify the exact format. And even worse: POSIX
182 defines this not at all. So we can use this feature only on selected
183 system (e.g. those using GNU C Library). */
185 # define HAVE_LOCALE_NULL
188 /* We want to allocate a string at the end of the struct. gcc makes
196 /* This is the type used for the search tree where known translations
198 struct known_translation_t
200 /* Domain in which to search. */
204 unsigned long int plindex
;
209 /* State of the catalog counter at the point the string was found. */
212 /* And finally the translation. */
213 const char *translation
;
215 /* Pointer to the string in question. */
219 /* Root of the search tree with known translations. We can use this
220 only if the system provides the `tsearch' function family. */
221 #if defined HAVE_TSEARCH || defined _LIBC
227 # define tsearch __tsearch
230 /* Function to compare two entries in the table of known translations. */
232 transcmp (const void *p1
, const void *p2
)
234 struct known_translation_t
*s1
= (struct known_translation_t
*) p1
;
235 struct known_translation_t
*s2
= (struct known_translation_t
*) p2
;
238 result
= strcmp (s1
->msgid
, s2
->msgid
);
241 result
= strcmp (s1
->domain
, s2
->domain
);
244 result
= s1
->plindex
- s2
->plindex
;
246 /* We compare the category last (though this is the cheapest
247 operation) since it is hopefully always the same (namely
249 result
= s1
->category
- s2
->category
;
257 /* Name of the default domain used for gettext(3) prior any call to
258 textdomain(3). The default value for this is "messages". */
259 const char _nl_default_default_domain
[] = "messages";
261 /* Value used as the default domain for gettext(3). */
262 const char *_nl_current_default_domain
= _nl_default_default_domain
;
264 /* Contains the default location of the message catalogs. */
265 const char _nl_default_dirname
[] = GNULOCALEDIR
;
267 /* List with bindings of specific domains created by bindtextdomain()
269 struct binding
*_nl_domain_bindings
;
271 /* Prototypes for local functions. */
272 static unsigned long int plural_eval (struct expression
*pexp
,
273 unsigned long int n
) internal_function
;
274 static const char *category_to_name
PARAMS ((int category
)) internal_function
;
275 static const char *guess_category_value
PARAMS ((int category
,
276 const char *categoryname
))
280 /* For those loosing systems which don't have `alloca' we have to add
281 some additional code emulating it. */
283 /* Nothing has to be done. */
284 # define ADD_BLOCK(list, address) /* nothing */
285 # define FREE_BLOCKS(list) /* nothing */
290 struct block_list
*next
;
292 # define ADD_BLOCK(list, addr) \
294 struct block_list *newp = (struct block_list *) malloc (sizeof (*newp)); \
295 /* If we cannot get a free block we cannot add the new element to \
297 if (newp != NULL) { \
298 newp->address = (addr); \
299 newp->next = (list); \
303 # define FREE_BLOCKS(list) \
305 while (list != NULL) { \
306 struct block_list *old = list; \
312 # define alloca(size) (malloc (size))
313 #endif /* have alloca */
316 /* Names for the libintl functions are a problem. They must not clash
317 with existing names and they should follow ANSI C. But this source
318 code is also used in GNU C Library where the names have a __
319 prefix. So we have to make a difference here. */
321 # define DCIGETTEXT __dcigettext
323 # define DCIGETTEXT dcigettext__
326 /* Lock variable to protect the global data in the gettext implementation. */
327 __libc_rwlock_define_initialized (, _nl_state_lock
)
329 /* Checking whether the binaries runs SUID must be done and glibc provides
330 easier methods therefore we make a difference here. */
332 # define ENABLE_SECURE __libc_enable_secure
333 # define DETERMINE_SECURE
335 static int enable_secure
;
336 # define ENABLE_SECURE (enable_secure == 1)
337 # define DETERMINE_SECURE \
338 if (enable_secure == 0) \
340 if (getuid () != geteuid () || getgid () != getegid ()) \
343 enable_secure = -1; \
347 /* Look up MSGID in the DOMAINNAME message catalog for the current
348 CATEGORY locale and, if PLURAL is nonzero, search over string
349 depending on the plural form determined by N. */
351 DCIGETTEXT (domainname
, msgid1
, msgid2
, plural
, n
, category
)
352 const char *domainname
;
360 struct block_list
*block_list
= NULL
;
362 struct loaded_l10nfile
*domain
;
363 struct binding
*binding
;
364 const char *categoryname
;
365 const char *categoryvalue
;
366 char *dirname
, *xdomainname
;
370 #if defined HAVE_TSEARCH || defined _LIBC
371 struct known_translation_t
*search
;
372 struct known_translation_t
**foundp
= NULL
;
375 size_t domainname_len
;
377 /* If no real MSGID is given return NULL. */
381 __libc_rwlock_rdlock (_nl_state_lock
);
383 /* If DOMAINNAME is NULL, we are interested in the default domain. If
384 CATEGORY is not LC_MESSAGES this might not make much sense but the
385 definition left this undefined. */
386 if (domainname
== NULL
)
387 domainname
= _nl_current_default_domain
;
389 #if defined HAVE_TSEARCH || defined _LIBC
390 msgid_len
= strlen (msgid1
) + 1;
394 /* Try to find the translation among those which we found at
396 search
= (struct known_translation_t
*) alloca (sizeof (*search
)
398 memcpy (search
->msgid
, msgid1
, msgid_len
);
399 search
->domain
= (char *) domainname
;
401 search
->category
= category
;
403 foundp
= (struct known_translation_t
**) tfind (search
, &root
, transcmp
);
404 if (foundp
!= NULL
&& (*foundp
)->counter
== _nl_msg_cat_cntr
)
406 __libc_rwlock_unlock (_nl_state_lock
);
407 return (char *) (*foundp
)->translation
;
412 /* Preserve the `errno' value. */
415 /* See whether this is a SUID binary or not. */
418 /* First find matching binding. */
419 for (binding
= _nl_domain_bindings
; binding
!= NULL
; binding
= binding
->next
)
421 int compare
= strcmp (domainname
, binding
->domainname
);
427 /* It is not in the list. */
434 dirname
= (char *) _nl_default_dirname
;
435 else if (binding
->dirname
[0] == '/')
436 dirname
= binding
->dirname
;
439 /* We have a relative path. Make it absolute now. */
440 size_t dirname_len
= strlen (binding
->dirname
) + 1;
444 path_max
= (unsigned int) PATH_MAX
;
445 path_max
+= 2; /* The getcwd docs say to do this. */
447 dirname
= (char *) alloca (path_max
+ dirname_len
);
448 ADD_BLOCK (block_list
, dirname
);
451 while ((ret
= getcwd (dirname
, path_max
)) == NULL
&& errno
== ERANGE
)
453 path_max
+= PATH_INCR
;
454 dirname
= (char *) alloca (path_max
+ dirname_len
);
455 ADD_BLOCK (block_list
, dirname
);
461 /* We cannot get the current working directory. Don't signal an
462 error but simply return the default string. */
463 FREE_BLOCKS (block_list
);
464 __set_errno (saved_errno
);
467 /* Use the Germanic plural rule. */
468 : n
== 1 ? (char *) msgid1
: (char *) msgid2
);
471 stpcpy (stpcpy (strchr (dirname
, '\0'), "/"), binding
->dirname
);
474 /* Now determine the symbolic name of CATEGORY and its value. */
475 categoryname
= category_to_name (category
);
476 categoryvalue
= guess_category_value (category
, categoryname
);
478 domainname_len
= strlen (domainname
);
479 xdomainname
= (char *) alloca (strlen (categoryname
)
480 + domainname_len
+ 5);
481 ADD_BLOCK (block_list
, xdomainname
);
483 stpcpy (mempcpy (stpcpy (stpcpy (xdomainname
, categoryname
), "/"),
484 domainname
, domainname_len
),
487 /* Creating working area. */
488 single_locale
= (char *) alloca (strlen (categoryvalue
) + 1);
489 ADD_BLOCK (block_list
, single_locale
);
492 /* Search for the given string. This is a loop because we perhaps
493 got an ordered list of languages to consider for the translation. */
496 /* Make CATEGORYVALUE point to the next element of the list. */
497 while (categoryvalue
[0] != '\0' && categoryvalue
[0] == ':')
499 if (categoryvalue
[0] == '\0')
501 /* The whole contents of CATEGORYVALUE has been searched but
502 no valid entry has been found. We solve this situation
503 by implicitly appending a "C" entry, i.e. no translation
505 single_locale
[0] = 'C';
506 single_locale
[1] = '\0';
510 char *cp
= single_locale
;
511 while (categoryvalue
[0] != '\0' && categoryvalue
[0] != ':')
512 *cp
++ = *categoryvalue
++;
515 /* When this is a SUID binary we must not allow accessing files
516 outside the dedicated directories. */
518 && (memchr (single_locale
, '/',
519 _nl_find_language (single_locale
) - single_locale
)
521 /* Ingore this entry. */
525 /* If the current locale value is C (or POSIX) we don't load a
526 domain. Return the MSGID. */
527 if (strcmp (single_locale
, "C") == 0
528 || strcmp (single_locale
, "POSIX") == 0)
530 FREE_BLOCKS (block_list
);
531 __libc_rwlock_unlock (_nl_state_lock
);
532 __set_errno (saved_errno
);
535 /* Use the Germanic plural rule. */
536 : n
== 1 ? (char *) msgid1
: (char *) msgid2
);
540 /* Find structure describing the message catalog matching the
541 DOMAINNAME and CATEGORY. */
542 domain
= _nl_find_domain (dirname
, single_locale
, xdomainname
, binding
);
546 unsigned long int index
= 0;
547 #if defined HAVE_TSEARCH || defined _LIBC
548 struct loaded_domain
*domaindata
=
549 (struct loaded_domain
*) domain
->data
;
553 /* Try to find the translation among those which we
554 found at some time. */
555 search
= (struct known_translation_t
*) alloca (sizeof (*search
)
557 memcpy (search
->msgid
, msgid1
, msgid_len
);
558 search
->domain
= (char *) domainname
;
559 search
->plindex
= plural_eval (domaindata
->plural
, n
);
560 if (search
->plindex
>= domaindata
->nplurals
)
561 /* This should never happen. It means the plural expression
562 and the given maximum value do not match. */
564 index
= search
->plindex
;
565 search
->category
= category
;
567 foundp
= (struct known_translation_t
**) tfind (search
, &root
,
569 if (foundp
!= NULL
&& (*foundp
)->counter
== _nl_msg_cat_cntr
)
571 __libc_rwlock_unlock (_nl_state_lock
);
572 return (char *) (*foundp
)->translation
;
577 retval
= _nl_find_msg (domain
, msgid1
, index
);
583 for (cnt
= 0; domain
->successor
[cnt
] != NULL
; ++cnt
)
585 retval
= _nl_find_msg (domain
->successor
[cnt
], msgid1
,
595 FREE_BLOCKS (block_list
);
596 __set_errno (saved_errno
);
597 #if defined HAVE_TSEARCH || defined _LIBC
600 /* Create a new entry and add it to the search tree. */
601 struct known_translation_t
*newp
;
603 newp
= (struct known_translation_t
*)
604 malloc (sizeof (*newp
) + msgid_len
605 + domainname_len
+ 1 - ZERO
);
608 newp
->domain
= mempcpy (newp
->msgid
, msgid1
, msgid_len
);
609 memcpy (newp
->domain
, domainname
, domainname_len
+ 1);
610 newp
->plindex
= index
;
611 newp
->category
= category
;
612 newp
->counter
= _nl_msg_cat_cntr
;
613 newp
->translation
= retval
;
615 /* Insert the entry in the search tree. */
616 foundp
= (struct known_translation_t
**)
617 tsearch (newp
, &root
, transcmp
);
619 || __builtin_expect (*foundp
!= newp
, 0))
620 /* The insert failed. */
626 /* We can update the existing entry. */
627 (*foundp
)->counter
= _nl_msg_cat_cntr
;
628 (*foundp
)->translation
= retval
;
631 __libc_rwlock_unlock (_nl_state_lock
);
642 _nl_find_msg (domain_file
, msgid
, index
)
643 struct loaded_l10nfile
*domain_file
;
645 unsigned long int index
;
647 struct loaded_domain
*domain
;
651 if (domain_file
->decided
== 0)
652 _nl_load_domain (domain_file
);
654 if (domain_file
->data
== NULL
)
657 domain
= (struct loaded_domain
*) domain_file
->data
;
659 /* Locate the MSGID and its translation. */
660 if (domain
->hash_size
> 2 && domain
->hash_tab
!= NULL
)
662 /* Use the hashing table. */
663 nls_uint32 len
= strlen (msgid
);
664 nls_uint32 hash_val
= hash_string (msgid
);
665 nls_uint32 idx
= hash_val
% domain
->hash_size
;
666 nls_uint32 incr
= 1 + (hash_val
% (domain
->hash_size
- 2));
667 nls_uint32 nstr
= W (domain
->must_swap
, domain
->hash_tab
[idx
]);
670 /* Hash table entry is empty. */
673 if (W (domain
->must_swap
, domain
->orig_tab
[nstr
- 1].length
) == len
675 domain
->data
+ W (domain
->must_swap
,
676 domain
->orig_tab
[nstr
- 1].offset
)) == 0)
684 if (idx
>= domain
->hash_size
- incr
)
685 idx
-= domain
->hash_size
- incr
;
689 nstr
= W (domain
->must_swap
, domain
->hash_tab
[idx
]);
691 /* Hash table entry is empty. */
694 if (W (domain
->must_swap
, domain
->orig_tab
[nstr
- 1].length
) == len
696 domain
->data
+ W (domain
->must_swap
,
697 domain
->orig_tab
[nstr
- 1].offset
))
708 /* Try the default method: binary search in the sorted array of
713 top
= domain
->nstrings
;
718 act
= (bottom
+ top
) / 2;
719 cmp_val
= strcmp (msgid
, (domain
->data
720 + W (domain
->must_swap
,
721 domain
->orig_tab
[act
].offset
)));
724 else if (cmp_val
> 0)
729 /* No translation was found. */
734 /* The translation was found at index ACT. If we have to convert the
735 string to use a different character set, this is the time. */
736 result
= ((char *) domain
->data
737 + W (domain
->must_swap
, domain
->trans_tab
[act
].offset
));
739 #if defined _LIBC || HAVE_ICONV
742 domain
->conv
!= (__gconv_t
) -1
745 domain
->conv
!= (iconv_t
) -1
750 /* We are supposed to do a conversion. First allocate an
751 appropriate table with the same structure as the table
752 of translations in the file, where we can put the pointers
753 to the converted strings in.
754 There is a slight complication with the INDEX: We don't know
755 a priori which entries are plural entries. Therefore at any
756 moment we can only translate the variants 0 .. INDEX. */
758 if (domain
->conv_tab
== NULL
759 && ((domain
->conv_tab
= (char **) calloc (domain
->nstrings
,
762 /* Mark that we didn't succeed allocating a table. */
763 domain
->conv_tab
= (char **) -1;
765 if (__builtin_expect (domain
->conv_tab
== (char **) -1, 0))
766 /* Nothing we can do, no more memory. */
769 if (domain
->conv_tab
[act
] == NULL
770 || *(nls_uint32
*) domain
->conv_tab
[act
] < index
)
772 /* We haven't used this string so far, so it is not
773 translated yet. Do this now. */
774 /* We use a bit more efficient memory handling.
775 We allocate always larger blocks which get used over
776 time. This is faster than many small allocations. */
777 __libc_lock_define_initialized (static, lock
)
778 static unsigned char *freemem
;
779 static size_t freemem_size
;
782 const unsigned char *inbuf
;
783 unsigned char *outbuf
;
785 /* Note that we translate (index + 1) consecutive strings at
786 once, including the final NUL byte. */
788 unsigned long int i
= index
;
793 resultlen
= p
- result
;
796 __libc_lock_lock (lock
);
799 outbuf
= freemem
+ sizeof (nls_uint32
);
804 size_t non_reversible
;
807 if (freemem_size
< 4)
810 res
= __gconv (domain
->conv
,
811 &inbuf
, inbuf
+ resultlen
,
813 outbuf
+ freemem_size
- sizeof (nls_uint32
),
816 if (res
== __GCONV_OK
|| res
== __GCONV_EMPTY_INPUT
)
819 if (res
!= __GCONV_FULL_OUTPUT
)
821 __libc_lock_unlock (lock
);
828 const char *inptr
= (const char *) inbuf
;
829 size_t inleft
= resultlen
;
830 char *outptr
= (char *) outbuf
;
833 if (freemem_size
< 4)
836 outleft
= freemem_size
- 4;
837 if (iconv (domain
->conv
, &inptr
, &inleft
, &outptr
, &outleft
)
840 outbuf
= (unsigned char *) outptr
;
845 __libc_lock_unlock (lock
);
852 /* We must resize the buffer. */
853 freemem_size
= 2 * freemem_size
;
854 if (freemem_size
< 4064)
856 freemem
= (char *) malloc (freemem_size
);
857 if (__builtin_expect (freemem
== NULL
, 0))
860 __libc_lock_unlock (lock
);
864 outbuf
= freemem
+ sizeof (nls_uint32
);
867 /* We have now in our buffer a converted string. Put this
868 into the table of conversions. */
869 *(nls_uint32
*) freemem
= index
;
870 domain
->conv_tab
[act
] = freemem
;
871 /* Shrink freemem, but keep it aligned. */
872 freemem_size
-= outbuf
- freemem
;
874 freemem
+= freemem_size
& (alignof (nls_uint32
) - 1);
875 freemem_size
= freemem_size
& ~ (alignof (nls_uint32
) - 1);
877 __libc_lock_unlock (lock
);
880 /* Now domain->conv_tab[act] contains the translation of at least
881 the variants 0 .. INDEX. */
882 result
= domain
->conv_tab
[act
] + sizeof (nls_uint32
);
886 /* The result string is converted. */
888 #endif /* _LIBC || HAVE_ICONV */
890 /* Now skip some strings. How much depends on the index passed in. */
894 result
= __rawmemchr (result
, '\0');
896 result
= strchr (result
, '\0');
898 /* And skip over the NUL byte. */
906 /* Function to evaluate the plural expression and return an index value. */
907 static unsigned long int
909 plural_eval (struct expression
*pexp
, unsigned long int n
)
911 switch (pexp
->operation
)
916 return pexp
->val
.num
;
918 return (plural_eval (pexp
->val
.args2
.left
, n
)
919 * plural_eval (pexp
->val
.args2
.right
, n
));
921 return (plural_eval (pexp
->val
.args2
.left
, n
)
922 / plural_eval (pexp
->val
.args2
.right
, n
));
924 return (plural_eval (pexp
->val
.args2
.left
, n
)
925 % plural_eval (pexp
->val
.args2
.right
, n
));
927 return (plural_eval (pexp
->val
.args2
.left
, n
)
928 + plural_eval (pexp
->val
.args2
.right
, n
));
930 return (plural_eval (pexp
->val
.args2
.left
, n
)
931 - plural_eval (pexp
->val
.args2
.right
, n
));
933 return (plural_eval (pexp
->val
.args2
.left
, n
)
934 == plural_eval (pexp
->val
.args2
.right
, n
));
936 return (plural_eval (pexp
->val
.args2
.left
, n
)
937 != plural_eval (pexp
->val
.args2
.right
, n
));
939 return (plural_eval (pexp
->val
.args2
.left
, n
)
940 && plural_eval (pexp
->val
.args2
.right
, n
));
942 return (plural_eval (pexp
->val
.args2
.left
, n
)
943 || plural_eval (pexp
->val
.args2
.right
, n
));
945 return (plural_eval (pexp
->val
.args3
.bexp
, n
)
946 ? plural_eval (pexp
->val
.args3
.tbranch
, n
)
947 : plural_eval (pexp
->val
.args3
.fbranch
, n
));
954 /* Return string representation of locale CATEGORY. */
957 category_to_name (category
)
966 retval
= "LC_COLLATE";
976 retval
= "LC_MONETARY";
981 retval
= "LC_NUMERIC";
991 retval
= "LC_MESSAGES";
996 retval
= "LC_RESPONSE";
1001 /* This might not make sense but is perhaps better than any other
1007 /* If you have a better idea for a default value let me know. */
1014 /* Guess value of current locale from value of the environment variables. */
1017 guess_category_value (category
, categoryname
)
1019 const char *categoryname
;
1023 /* The highest priority value is the `LANGUAGE' environment
1024 variable. This is a GNU extension. */
1025 retval
= getenv ("LANGUAGE");
1026 if (retval
!= NULL
&& retval
[0] != '\0')
1029 /* `LANGUAGE' is not set. So we have to proceed with the POSIX
1030 methods of looking to `LC_ALL', `LC_xxx', and `LANG'. On some
1031 systems this can be done by the `setlocale' function itself. */
1032 #if defined HAVE_SETLOCALE && defined HAVE_LC_MESSAGES && defined HAVE_LOCALE_NULL
1033 return setlocale (category
, NULL
);
1035 /* Setting of LC_ALL overwrites all other. */
1036 retval
= getenv ("LC_ALL");
1037 if (retval
!= NULL
&& retval
[0] != '\0')
1040 /* Next comes the name of the desired category. */
1041 retval
= getenv (categoryname
);
1042 if (retval
!= NULL
&& retval
[0] != '\0')
1045 /* Last possibility is the LANG environment variable. */
1046 retval
= getenv ("LANG");
1047 if (retval
!= NULL
&& retval
[0] != '\0')
1050 /* We use C as the default domain. POSIX says this is implementation
1056 /* @@ begin of epilog @@ */
1058 /* We don't want libintl.a to depend on any other library. So we
1059 avoid the non-standard function stpcpy. In GNU C Library this
1060 function is available, though. Also allow the symbol HAVE_STPCPY
1062 #if !_LIBC && !HAVE_STPCPY
1068 while ((*dest
++ = *src
++) != '\0')
1074 #if !_LIBC && !HAVE_MEMPCPY
1076 mempcpy (dest
, src
, n
)
1081 return (void *) ((char *) memcpy (dest
, src
, n
) + n
);
1087 /* If we want to free all resources we have to do some work at
1089 static void __attribute__ ((unused
))
1092 struct binding
*runp
;
1094 for (runp
= _nl_domain_bindings
; runp
!= NULL
; runp
= runp
->next
)
1096 if (runp
->dirname
!= _nl_default_dirname
)
1097 /* Yes, this is a pointer comparison. */
1098 free (runp
->dirname
);
1099 if (runp
->codeset
!= NULL
)
1100 free (runp
->codeset
);
1103 if (_nl_current_default_domain
!= _nl_default_default_domain
)
1104 /* Yes, again a pointer comparison. */
1105 free ((char *) _nl_current_default_domain
);
1107 /* Remove the search tree with the known translations. */
1108 __tdestroy (root
, free
);
1111 text_set_element (__libc_subfreeres
, free_mem
);