Back to Evolution Project page
00001 /* Implementation of the textdomain(3) function. 00002 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. 00003 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2, or (at your option) 00008 any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software Foundation, 00017 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00018 00019 #ifdef HAVE_CONFIG_H 00020 # include <config.h> 00021 #endif 00022 00023 #if defined STDC_HEADERS || defined _LIBC 00024 # include <stdlib.h> 00025 #endif 00026 00027 #if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC 00028 # include <string.h> 00029 #else 00030 # include <strings.h> 00031 # ifndef memcpy 00032 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num) 00033 # endif 00034 #endif 00035 00036 #ifdef _LIBC 00037 # include <libintl.h> 00038 #else 00039 # include "libgettext.h" 00040 #endif 00041 00042 /* @@ end of prolog @@ */ 00043 00044 /* Name of the default text domain. */ 00045 extern const char _nl_default_default_domain[]; 00046 00047 /* Default text domain in which entries for gettext(3) are to be found. */ 00048 extern const char *_nl_current_default_domain; 00049 00050 00051 /* Names for the libintl functions are a problem. They must not clash 00052 with existing names and they should follow ANSI C. But this source 00053 code is also used in GNU C Library where the names have a __ 00054 prefix. So we have to make a difference here. */ 00055 #ifdef _LIBC 00056 # define TEXTDOMAIN __textdomain 00057 # ifndef strdup 00058 # define strdup(str) __strdup (str) 00059 # endif 00060 #else 00061 # define TEXTDOMAIN textdomain__ 00062 #endif 00063 00064 /* Set the current default message catalog to DOMAINNAME. 00065 If DOMAINNAME is null, return the current default. 00066 If DOMAINNAME is "", reset to the default of "messages". */ 00067 char * 00068 TEXTDOMAIN (domainname) 00069 const char *domainname; 00070 { 00071 char *old; 00072 00073 /* A NULL pointer requests the current setting. */ 00074 if (domainname == NULL) 00075 return (char *) _nl_current_default_domain; 00076 00077 old = (char *) _nl_current_default_domain; 00078 00079 /* If domain name is the null string set to default domain "messages". */ 00080 if (domainname[0] == '\0' 00081 || strcmp (domainname, _nl_default_default_domain) == 0) 00082 _nl_current_default_domain = _nl_default_default_domain; 00083 else 00084 { 00085 /* If the following malloc fails `_nl_current_default_domain' 00086 will be NULL. This value will be returned and so signals we 00087 are out of core. */ 00088 #if defined _LIBC || defined HAVE_STRDUP 00089 _nl_current_default_domain = strdup (domainname); 00090 #else 00091 size_t len = strlen (domainname) + 1; 00092 char *cp = (char *) malloc (len); 00093 if (cp != NULL) 00094 memcpy (cp, domainname, len); 00095 _nl_current_default_domain = cp; 00096 #endif 00097 } 00098 00099 if (old != _nl_default_default_domain) 00100 free (old); 00101 00102 return (char *) _nl_current_default_domain; 00103 } 00104 00105 #ifdef _LIBC 00106 /* Alias for function name in GNU C Library. */ 00107 weak_alias (__textdomain, textdomain); 00108 #endif