1 /* textdomain.c -- implementation of the textdomain(3) function
2 Copyright (C) 1995 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
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #if defined STDC_HEADERS || defined _LIBC
26 #if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC
35 # include "libgettext.h"
38 /* @@ end of prolog @@ */
40 /* Name of the default text domain. */
41 extern const char _nl_default_default_domain
[];
43 /* Default text domain in which entries for gettext(3) are to be found. */
44 extern const char *_nl_current_default_domain
;
47 /* Names for the libintl functions are a problem. They must not clash
48 with existing names and they should follow ANSI C. But this source
49 code is also used in GNU C Library where the names have a __
50 prefix. So we have to make a difference here. */
52 # define TEXTDOMAIN __textdomain
54 # define TEXTDOMAIN textdomain__
57 /* Set the current default message catalog to DOMAINNAME.
58 If DOMAINNAME is null, return the current default.
59 If DOMAINNAME is "", reset to the default of "messages". */
61 TEXTDOMAIN (domainname
)
62 const char *domainname
;
66 /* A NULL pointer requests the current setting. */
67 if (domainname
== NULL
)
68 return (char *) _nl_current_default_domain
;
70 old
= (char *) _nl_current_default_domain
;
72 /* If domain name is the null string set to default domain "messages". */
73 if (domainname
[0] == '\0'
74 || strcmp (domainname
, _nl_default_default_domain
) == 0)
75 _nl_current_default_domain
= _nl_default_default_domain
;
78 /* If the following malloc fails `_nl_current_default_domain'
79 will be NULL. This value will be returned and so signals we
81 size_t len
= strlen (domainname
) + 1;
82 char *cp
= (char *) malloc (len
);
84 memcpy (cp
, domainname
, len
);
85 _nl_current_default_domain
= cp
;
88 if (old
!= _nl_default_default_domain
)
91 return (char *) _nl_current_default_domain
;
95 /* Alias for function name in GNU C Library. */
96 weak_alias (__textdomain
, textdomain
);