1 /* bindtextdom.c -- implementation of the bindtextdomain(3) function
2 Copyright (C) 1995 Free Software Foundation, Inc.
4 This file is part of the GNU C Library. Its master source is NOT part of
5 the C library, however. The master source lives in /gd/gnu/lib.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If
19 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
20 Cambridge, MA 02139, USA. */
26 #if defined STDC_HEADERS || defined _LIBC
36 #if defined HAVE_STRING_H || defined _LIBC
45 # include "libgettext.h"
50 /* @@ end of prolog @@ */
52 /* Contains the default location of the message catalogs. */
53 extern const char _nl_default_dirname
[];
55 /* List with bindings of specific domains. */
56 extern struct binding
*_nl_domain_bindings
;
59 /* Names for the libintl functions are a problem. They must not clash
60 with existing names and they should follow ANSI C. But this source
61 code is also used in GNU C Library where the names have a __
62 prefix. So we have to make a difference here. */
64 # define BINDTEXTDOMAIN __bindtextdomain
66 # define BINDTEXTDOMAIN bindtextdomain__
69 /* Specify that the DOMAINNAME message catalog will be found
70 in DIRNAME rather than in the system locale data base. */
72 BINDTEXTDOMAIN (domainname
, dirname
)
73 const char *domainname
;
76 struct binding
*binding
;
78 /* Some sanity checks. */
79 if (domainname
== NULL
|| domainname
[0] == '\0')
82 for (binding
= _nl_domain_bindings
; binding
!= NULL
; binding
= binding
->next
)
84 int compare
= strcmp (domainname
, binding
->domainname
);
90 /* It is not in the list. */
97 /* The current binding has be to returned. */
98 return binding
== NULL
? (char *) _nl_default_dirname
: binding
->dirname
;
102 /* The domain is already bound. Replace the old binding. */
105 if (strcmp (dirname
, _nl_default_dirname
) == 0)
106 new_dirname
= (char *) _nl_default_dirname
;
109 size_t len
= strlen (dirname
) + 1;
110 new_dirname
= (char *) malloc (len
);
111 if (new_dirname
== NULL
)
114 memcpy (new_dirname
, dirname
, len
);
117 if (strcmp (binding
->dirname
, _nl_default_dirname
) != 0)
118 free (binding
->dirname
);
120 binding
->dirname
= new_dirname
;
124 /* We have to create a new binding. */
126 struct binding
*new_binding
=
127 (struct binding
*) malloc (sizeof (*new_binding
));
129 if (new_binding
== NULL
)
132 len
= strlen (domainname
) + 1;
133 new_binding
->domainname
= (char *) malloc (len
);
134 if (new_binding
->domainname
== NULL
)
136 memcpy (new_binding
->domainname
, domainname
, len
);
138 if (strcmp (dirname
, _nl_default_dirname
) == 0)
139 new_binding
->dirname
= (char *) _nl_default_dirname
;
142 len
= strlen (dirname
) + 1;
143 new_binding
->dirname
= (char *) malloc (len
);
144 if (new_binding
->dirname
== NULL
)
146 memcpy (new_binding
->dirname
, dirname
, len
);
149 /* Now enqueue it. */
150 if (_nl_domain_bindings
== NULL
151 || strcmp (domainname
, _nl_domain_bindings
->domainname
) < 0)
153 new_binding
->next
= _nl_domain_bindings
;
154 _nl_domain_bindings
= new_binding
;
158 binding
= _nl_domain_bindings
;
159 while (binding
->next
!= NULL
160 && strcmp (domainname
, binding
->next
->domainname
) > 0)
161 binding
= binding
->next
;
163 new_binding
->next
= binding
->next
;
164 binding
->next
= new_binding
;
167 binding
= new_binding
;
170 return binding
->dirname
;
174 /* Alias for function name in GNU C Library. */
175 weak_alias (__bindtextdomain
, bindtextdomain
);