00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00035 # include <bits/libc-lock.h>
00036 #else
00037
00038 # define __libc_rwlock_define(CLASS, NAME)
00039 # define __libc_rwlock_wrlock(NAME)
00040 # define __libc_rwlock_unlock(NAME)
00041 #endif
00042
00043
00044
00045
00046 #if !defined _LIBC
00047 # define _nl_default_default_domain _nl_default_default_domain__
00048 # define _nl_current_default_domain _nl_current_default_domain__
00049 #endif
00050
00051
00052
00053
00054 extern const char _nl_default_default_domain[];
00055
00056
00057 extern const char *_nl_current_default_domain;
00058
00059
00060
00061
00062
00063
00064 #ifdef _LIBC
00065 # define TEXTDOMAIN __textdomain
00066 # ifndef strdup
00067 # define strdup(str) __strdup (str)
00068 # endif
00069 #else
00070 # define TEXTDOMAIN textdomain__
00071 #endif
00072
00073
00074 __libc_rwlock_define (extern, _nl_state_lock)
00075
00076
00077
00078
00079 char *
00080 TEXTDOMAIN (domainname)
00081 const char *domainname;
00082 {
00083 char *new_domain;
00084 char *old_domain;
00085
00086
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
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
00103
00104 new_domain = old_domain;
00105 else
00106 {
00107
00108
00109
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
00124
00125
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
00141 weak_alias (__textdomain, textdomain);
00142 #endif