Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

textdomain.c

00001 /* Implementation of the textdomain(3) function.
00002    Copyright (C) 1995-1998, 2000, 2001, 2002 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU Library General Public License as published
00006    by the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00017    USA.  */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 # include <config.h>
00021 #endif
00022 
00023 #include <stdlib.h>
00024 #include <string.h>
00025 
00026 #ifdef _LIBC
00027 # include <libintl.h>
00028 #else
00029 # include "libgnuintl.h"
00030 #endif
00031 #include "gettextP.h"
00032 
00033 #ifdef _LIBC
00034 /* We have to handle multi-threaded applications.  */
00035 # include <bits/libc-lock.h>
00036 #else
00037 /* Provide dummy implementation if this is outside glibc.  */
00038 # define __libc_rwlock_define(CLASS, NAME)
00039 # define __libc_rwlock_wrlock(NAME)
00040 # define __libc_rwlock_unlock(NAME)
00041 #endif
00042 
00043 /* The internal variables in the standalone libintl.a must have different
00044    names than the internal variables in GNU libc, otherwise programs
00045    using libintl.a cannot be linked statically.  */
00046 #if !defined _LIBC
00047 # define _nl_default_default_domain libintl_nl_default_default_domain
00048 # define _nl_current_default_domain libintl_nl_current_default_domain
00049 #endif
00050 
00051 /* @@ end of prolog @@ */
00052 
00053 /* Name of the default text domain.  */
00054 extern const char _nl_default_default_domain[] attribute_hidden;
00055 
00056 /* Default text domain in which entries for gettext(3) are to be found.  */
00057 extern const char *_nl_current_default_domain attribute_hidden;
00058 
00059 
00060 /* Names for the libintl functions are a problem.  They must not clash
00061    with existing names and they should follow ANSI C.  But this source
00062    code is also used in GNU C Library where the names have a __
00063    prefix.  So we have to make a difference here.  */
00064 #ifdef _LIBC
00065 # define TEXTDOMAIN __textdomain
00066 # ifndef strdup
00067 #  define strdup(str) __strdup (str)
00068 # endif
00069 #else
00070 # define TEXTDOMAIN libintl_textdomain
00071 #endif
00072 
00073 /* Lock variable to protect the global data in the gettext implementation.  */
00074 __libc_rwlock_define (extern, _nl_state_lock attribute_hidden)
00075 
00076 /* Set the current default message catalog to DOMAINNAME.
00077    If DOMAINNAME is null, return the current default.
00078    If DOMAINNAME is "", reset to the default of "messages".  */
00079 char *
00080 TEXTDOMAIN (domainname)
00081      const char *domainname;
00082 {
00083   char *new_domain;
00084   char *old_domain;
00085 
00086   /* A NULL pointer requests the current setting.  */
00087   if (domainname == NULL)
00088     return (char *) _nl_current_default_domain;
00089 
00090   __libc_rwlock_wrlock (_nl_state_lock);
00091 
00092   old_domain = (char *) _nl_current_default_domain;
00093 
00094   /* If domain name is the null string set to default domain "messages".  */
00095   if (domainname[0] == '\0'
00096       || strcmp (domainname, _nl_default_default_domain) == 0)
00097     {
00098       _nl_current_default_domain = _nl_default_default_domain;
00099       new_domain = (char *) _nl_current_default_domain;
00100     }
00101   else if (strcmp (domainname, old_domain) == 0)
00102     /* This can happen and people will use it to signal that some
00103        environment variable changed.  */
00104     new_domain = old_domain;
00105   else
00106     {
00107       /* If the following malloc fails `_nl_current_default_domain'
00108          will be NULL.  This value will be returned and so signals we
00109          are out of core.  */
00110 #if defined _LIBC || defined HAVE_STRDUP
00111       new_domain = strdup (domainname);
00112 #else
00113       size_t len = strlen (domainname) + 1;
00114       new_domain = (char *) malloc (len);
00115       if (new_domain != NULL)
00116         memcpy (new_domain, domainname, len);
00117 #endif
00118 
00119       if (new_domain != NULL)
00120         _nl_current_default_domain = new_domain;
00121     }
00122 
00123   /* We use this possibility to signal a change of the loaded catalogs
00124      since this is most likely the case and there is no other easy we
00125      to do it.  Do it only when the call was successful.  */
00126   if (new_domain != NULL)
00127     {
00128       ++_nl_msg_cat_cntr;
00129 
00130       if (old_domain != new_domain && old_domain != _nl_default_default_domain)
00131         free (old_domain);
00132     }
00133 
00134   __libc_rwlock_unlock (_nl_state_lock);
00135 
00136   return new_domain;
00137 }
00138 
00139 #ifdef _LIBC
00140 /* Alias for function name in GNU C Library.  */
00141 weak_alias (__textdomain, textdomain);
00142 #endif

Generated on Tue Dec 20 10:14:20 2005 for vlc-0.8.4a by  doxygen 1.4.2