Sun Dec 17 15:56:35 1995 Miles Bader <miles@gnu.ai.mit.edu>
[glibc.git] / intl / textdomain.c
blobc06642b2680658d74d0298088dbc8a340b9783ba
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)
7 any later version.
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. */
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
22 #if defined STDC_HEADERS || defined _LIBC
23 # include <stdlib.h>
24 #endif
26 #if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC
27 # include <string.h>
28 #else
29 # include <strings.h>
30 #endif
32 #ifdef _LIBC
33 # include <libintl.h>
34 #else
35 # include "libgettext.h"
36 #endif
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. */
51 #ifdef _LIBC
52 # define TEXTDOMAIN __textdomain
53 #else
54 # define TEXTDOMAIN textdomain__
55 #endif
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". */
60 char *
61 TEXTDOMAIN (domainname)
62 const char *domainname;
64 char *old;
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;
76 else
78 /* If the following malloc fails `_nl_current_default_domain'
79 will be NULL. This value will be returned and so signals we
80 are out of core. */
81 size_t len = strlen (domainname) + 1;
82 char *cp = (char *) malloc (len);
83 if (cp != NULL)
84 memcpy (cp, domainname, len);
85 _nl_current_default_domain = cp;
88 if (old != _nl_default_default_domain)
89 free (old);
91 return (char *) _nl_current_default_domain;
94 #ifdef _LIBC
95 /* Alias for function name in GNU C Library. */
96 weak_alias (__textdomain, textdomain);
97 #endif