1 /* Implementation of the textdomain(3) function.
2 Copyright (C) 1995-1998, 2000-2003, 2005-2006 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published
6 by the Free Software Foundation; either version 2, or (at your option)
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 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 this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
30 # include "libgnuintl.h"
33 /* Handle multi-threaded applications. */
35 # include <bits/libc-lock.h>
36 # define gl_rwlock_define __libc_rwlock_define
37 # define gl_rwlock_wrlock __libc_rwlock_wrlock
38 # define gl_rwlock_unlock __libc_rwlock_unlock
43 /* @@ end of prolog @@ */
46 /* Names for the libintl functions are a problem. They must not clash
47 with existing names and they should follow ANSI C. But this source
48 code is also used in GNU C Library where the names have a __
49 prefix. So we have to make a difference here. */
51 # define TEXTDOMAIN __textdomain
53 # define strdup(str) __strdup (str)
56 # define TEXTDOMAIN libintl_textdomain
59 /* Lock variable to protect the global data in the gettext implementation. */
60 gl_rwlock_define (extern, _nl_state_lock attribute_hidden
)
62 /* Set the current default message catalog to DOMAINNAME.
63 If DOMAINNAME is null, return the current default.
64 If DOMAINNAME is "", reset to the default of "messages". */
66 TEXTDOMAIN (const char *domainname
)
71 /* A NULL pointer requests the current setting. */
72 if (domainname
== NULL
)
73 return (char *) _nl_current_default_domain
;
75 gl_rwlock_wrlock (_nl_state_lock
);
77 old_domain
= (char *) _nl_current_default_domain
;
79 /* If domain name is the null string set to default domain "messages". */
80 if (domainname
[0] == '\0'
81 || strcmp (domainname
, _nl_default_default_domain
) == 0)
83 _nl_current_default_domain
= _nl_default_default_domain
;
84 new_domain
= (char *) _nl_current_default_domain
;
86 else if (strcmp (domainname
, old_domain
) == 0)
87 /* This can happen and people will use it to signal that some
88 environment variable changed. */
89 new_domain
= old_domain
;
92 /* If the following malloc fails `_nl_current_default_domain'
93 will be NULL. This value will be returned and so signals we
95 #if defined _LIBC || defined HAVE_STRDUP
96 new_domain
= strdup (domainname
);
98 size_t len
= strlen (domainname
) + 1;
99 new_domain
= (char *) malloc (len
);
100 if (new_domain
!= NULL
)
101 memcpy (new_domain
, domainname
, len
);
104 if (new_domain
!= NULL
)
105 _nl_current_default_domain
= new_domain
;
108 /* We use this possibility to signal a change of the loaded catalogs
109 since this is most likely the case and there is no other easy we
110 to do it. Do it only when the call was successful. */
111 if (new_domain
!= NULL
)
115 if (old_domain
!= new_domain
&& old_domain
!= _nl_default_default_domain
)
119 gl_rwlock_unlock (_nl_state_lock
);
125 /* Alias for function name in GNU C Library. */
126 weak_alias (__textdomain
, textdomain
);