]> git.lyx.org Git - lyx.git/blobdiff - intl/bindtextdom.c
Small fixes
[lyx.git] / intl / bindtextdom.c
index bc0f2c4b2d65f7d800f390cf190db7e03f049177..d9c3f349e04dee8aad8a06ecc76cacc4ccc187ba 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the bindtextdomain(3) function
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998 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
@@ -61,6 +61,9 @@ extern struct binding *_nl_domain_bindings;
    prefix.  So we have to make a difference here.  */
 #ifdef _LIBC
 # define BINDTEXTDOMAIN __bindtextdomain
+# ifndef strdup
+#  define strdup(str) __strdup (str)
+# endif
 #else
 # define BINDTEXTDOMAIN bindtextdomain__
 #endif
@@ -98,51 +101,76 @@ 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
     {
       /* We have to create a new binding.  */
+#if !defined _LIBC && !defined HAVE_STRDUP
       size_t len;
+#endif
       struct binding *new_binding =
        (struct binding *) malloc (sizeof (*new_binding));
 
       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.  */