1 /* Implementation of the textdomain(3) function.
2 Copyright (C) 1995-1998, 2000, 2001 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 General Public License as published by
6 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "intl/gettext/libintl.h"
28 #include "intl/gettext/gettextP.h"
29 #include "util/string.h"
31 /* Name of the default text domain. */
32 extern const unsigned char _nl_default_default_domain__
[];
34 /* Default text domain in which entries for gettext(3) are to be found. */
35 extern const unsigned char *_nl_current_default_domain__
;
37 /* Set the current default message catalog to DOMAINNAME.
38 If DOMAINNAME is null, return the current default.
39 If DOMAINNAME is "", reset to the default of "messages". */
41 textdomain__(const unsigned char *domainname
)
43 unsigned char *new_domain
;
44 unsigned char *old_domain
;
46 /* A NULL pointer requests the current setting. */
47 if (domainname
== NULL
)
48 return (unsigned char *) _nl_current_default_domain__
;
50 old_domain
= (unsigned char *) _nl_current_default_domain__
;
52 /* If domain name is the null string set to default domain "messages". */
53 if (domainname
[0] == '\0'
54 || strcmp(domainname
, _nl_default_default_domain__
) == 0) {
55 _nl_current_default_domain__
= _nl_default_default_domain__
;
56 new_domain
= (unsigned char *) _nl_current_default_domain__
;
57 } else if (strcmp(domainname
, old_domain
) == 0)
58 /* This can happen and people will use it to signal that some
59 environment variable changed. */
60 new_domain
= old_domain
;
62 /* If the following malloc fails `_nl_current_default_domain__'
63 will be NULL. This value will be returned and so signals we
65 new_domain
= strdup(domainname
);
67 if (new_domain
!= NULL
)
68 _nl_current_default_domain__
= new_domain
;
71 /* We use this possibility to signal a change of the loaded catalogs
72 since this is most likely the case and there is no other easy we
73 to do it. Do it only when the call was successful. */
74 if (new_domain
!= NULL
) {
77 if (old_domain
!= new_domain
78 && old_domain
!= _nl_default_default_domain__
)