diff options
Diffstat (limited to 'gnu/usr.bin/texinfo/intl/bindtextdom.c')
-rw-r--r-- | gnu/usr.bin/texinfo/intl/bindtextdom.c | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/gnu/usr.bin/texinfo/intl/bindtextdom.c b/gnu/usr.bin/texinfo/intl/bindtextdom.c index 72583f25783..9fcb8d9f29b 100644 --- a/gnu/usr.bin/texinfo/intl/bindtextdom.c +++ b/gnu/usr.bin/texinfo/intl/bindtextdom.c @@ -1,5 +1,5 @@ -/* bindtextdom.c -- implementation of the bindtextdomain(3) function - Copyright (C) 1995, 1996 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 @@ -34,7 +34,7 @@ void free (); #else # include <strings.h> # ifndef memcpy -# define memcpy(Dst, Src, Num) bcopy ((Src), (Dst), (Num)) +# define memcpy(Dst, Src, Num) bcopy (Src, Dst, Num) # endif #endif @@ -61,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 @@ -98,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 { @@ -128,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. */ |