diff options
Diffstat (limited to 'intl/bindtextdom.c')
-rw-r--r-- | intl/bindtextdom.c | 85 |
1 files changed, 56 insertions, 29 deletions
diff --git a/intl/bindtextdom.c b/intl/bindtextdom.c index bd9f4226..9fcb8d9f 100644 --- a/intl/bindtextdom.c +++ b/intl/bindtextdom.c @@ -1,19 +1,19 @@ -/* bindtextdom.c -- implementation of the bindtextdomain(3) function - Copyright (C) 1995 Free Software Foundation, Inc. +/* Implementation of the bindtextdomain(3) function + Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H # include <config.h> @@ -33,6 +33,9 @@ void free (); # include <string.h> #else # include <strings.h> +# ifndef memcpy +# define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num) +# endif #endif #ifdef _LIBC @@ -58,6 +61,7 @@ extern struct binding *_nl_domain_bindings; prefix. So we have to make a difference here. */ #ifdef _LIBC # define BINDTEXTDOMAIN __bindtextdomain +# define strdup(str) __strdup (str) #else # define BINDTEXTDOMAIN bindtextdomain__ #endif @@ -95,25 +99,36 @@ BINDTEXTDOMAIN (domainname, dirname) if (binding != NULL) { - /* The domain is already bound. Replace the old binding. */ - char *new_dirname; - - if (strcmp (dirname, _nl_default_dirname) == 0) - new_dirname = (char *) _nl_default_dirname; - else + /* The domain is already bound. If the new value and the old + one are equal we simply do nothing. Otherwise replace the + old binding. */ + if (strcmp (dirname, binding->dirname) != 0) { - size_t len = strlen (dirname) + 1; - new_dirname = (char *) malloc (len); - if (new_dirname == NULL) - return NULL; + char *new_dirname; + + if (strcmp (dirname, _nl_default_dirname) == 0) + new_dirname = (char *) _nl_default_dirname; + else + { +#if defined _LIBC || defined HAVE_STRDUP + new_dirname = strdup (dirname); + if (new_dirname == NULL) + return NULL; +#else + size_t len = strlen (dirname) + 1; + new_dirname = (char *) malloc (len); + if (new_dirname == NULL) + return NULL; - memcpy (new_dirname, dirname, len); - } + memcpy (new_dirname, dirname, len); +#endif + } - if (strcmp (binding->dirname, _nl_default_dirname) != 0) - free (binding->dirname); + if (binding->dirname != _nl_default_dirname) + free (binding->dirname); - binding->dirname = new_dirname; + binding->dirname = new_dirname; + } } else { @@ -125,21 +140,33 @@ BINDTEXTDOMAIN (domainname, dirname) if (new_binding == NULL) return NULL; +#if defined _LIBC || defined HAVE_STRDUP + new_binding->domainname = strdup (domainname); + if (new_binding->domainname == NULL) + return NULL; +#else len = strlen (domainname) + 1; new_binding->domainname = (char *) malloc (len); if (new_binding->domainname == NULL) - return NULL; + return NULL; memcpy (new_binding->domainname, domainname, len); +#endif if (strcmp (dirname, _nl_default_dirname) == 0) new_binding->dirname = (char *) _nl_default_dirname; else { +#if defined _LIBC || defined HAVE_STRDUP + new_binding->dirname = strdup (dirname); + if (new_binding->dirname == NULL) + return NULL; +#else len = strlen (dirname) + 1; new_binding->dirname = (char *) malloc (len); if (new_binding->dirname == NULL) return NULL; memcpy (new_binding->dirname, dirname, len); +#endif } /* Now enqueue it. */ |