1 /* Implementation of the bindtextdomain(3) function
2 Copyright (C) 1995, 1996, 1997, 1998 Free 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 Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 #if defined STDC_HEADERS || defined _LIBC
32 #if defined HAVE_STRING_H || defined _LIBC
37 # define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num)
44 # include "libgettext.h"
49 /* The internal variables in the standalone libintl.a must have different
50 names than the internal variables in GNU libc, otherwise programs
51 using libintl.a cannot be linked statically. */
53 # define _nl_default_dirname _nl_default_dirname__
54 # define _nl_domain_bindings _nl_domain_bindings__
57 /* @@ end of prolog @@ */
59 /* Contains the default location of the message catalogs. */
60 extern const char _nl_default_dirname
[];
62 /* List with bindings of specific domains. */
63 extern struct binding
*_nl_domain_bindings
;
66 /* Names for the libintl functions are a problem. They must not clash
67 with existing names and they should follow ANSI C. But this source
68 code is also used in GNU C Library where the names have a __
69 prefix. So we have to make a difference here. */
71 # define BINDTEXTDOMAIN __bindtextdomain
73 # define strdup(str) __strdup (str)
76 # define BINDTEXTDOMAIN bindtextdomain__
79 /* Specify that the DOMAINNAME message catalog will be found
80 in DIRNAME rather than in the system locale data base. */
82 BINDTEXTDOMAIN (domainname
, dirname
)
83 const char *domainname
;
86 struct binding
*binding
;
88 /* Some sanity checks. */
89 if (domainname
== NULL
|| domainname
[0] == '\0')
92 for (binding
= _nl_domain_bindings
; binding
!= NULL
; binding
= binding
->next
)
94 int compare
= strcmp (domainname
, binding
->domainname
);
100 /* It is not in the list. */
107 /* The current binding has be to returned. */
108 return binding
== NULL
? (char *) _nl_default_dirname
: binding
->dirname
;
112 /* The domain is already bound. If the new value and the old
113 one are equal we simply do nothing. Otherwise replace the
115 if (strcmp (dirname
, binding
->dirname
) != 0)
119 if (strcmp (dirname
, _nl_default_dirname
) == 0)
120 new_dirname
= (char *) _nl_default_dirname
;
123 #if defined _LIBC || defined HAVE_STRDUP
124 new_dirname
= strdup (dirname
);
125 if (new_dirname
== NULL
)
128 size_t len
= strlen (dirname
) + 1;
129 new_dirname
= (char *) malloc (len
);
130 if (new_dirname
== NULL
)
133 memcpy (new_dirname
, dirname
, len
);
137 if (binding
->dirname
!= _nl_default_dirname
)
138 free (binding
->dirname
);
140 binding
->dirname
= new_dirname
;
145 /* We have to create a new binding. */
146 #if !defined _LIBC && !defined HAVE_STRDUP
149 struct binding
*new_binding
=
150 (struct binding
*) malloc (sizeof (*new_binding
));
152 if (new_binding
== NULL
)
155 #if defined _LIBC || defined HAVE_STRDUP
156 new_binding
->domainname
= strdup (domainname
);
157 if (new_binding
->domainname
== NULL
)
160 len
= strlen (domainname
) + 1;
161 new_binding
->domainname
= (char *) malloc (len
);
162 if (new_binding
->domainname
== NULL
)
164 memcpy (new_binding
->domainname
, domainname
, len
);
167 if (strcmp (dirname
, _nl_default_dirname
) == 0)
168 new_binding
->dirname
= (char *) _nl_default_dirname
;
171 #if defined _LIBC || defined HAVE_STRDUP
172 new_binding
->dirname
= strdup (dirname
);
173 if (new_binding
->dirname
== NULL
)
176 len
= strlen (dirname
) + 1;
177 new_binding
->dirname
= (char *) malloc (len
);
178 if (new_binding
->dirname
== NULL
)
180 memcpy (new_binding
->dirname
, dirname
, len
);
184 /* Now enqueue it. */
185 if (_nl_domain_bindings
== NULL
186 || strcmp (domainname
, _nl_domain_bindings
->domainname
) < 0)
188 new_binding
->next
= _nl_domain_bindings
;
189 _nl_domain_bindings
= new_binding
;
193 binding
= _nl_domain_bindings
;
194 while (binding
->next
!= NULL
195 && strcmp (domainname
, binding
->next
->domainname
) > 0)
196 binding
= binding
->next
;
198 new_binding
->next
= binding
->next
;
199 binding
->next
= new_binding
;
202 binding
= new_binding
;
205 return binding
->dirname
;
209 /* Alias for function name in GNU C Library. */
210 weak_alias (__bindtextdomain
, bindtextdomain
);