]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
pullup:
authorAndreas Gustafsson <source@isc.org>
Thu, 1 Nov 2001 19:00:47 +0000 (19:00 +0000)
committerAndreas Gustafsson <source@isc.org>
Thu, 1 Nov 2001 19:00:47 +0000 (19:00 +0000)
1084.   [cleanup]       libbind: gai_strerror() rewritten.

CHANGES
lib/bind/irs/gai_strerror.c

diff --git a/CHANGES b/CHANGES
index f186b521c16765006e5e29f25c2f1c9bc3e1634d..f17d55cca773677fbe2d693815458ed25f21f19a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,8 @@
+
+       --- 9.2.0rc9 released ---
+
+1084.  [cleanup]       libbind: gai_strerror() rewritten.
+
 1083.  [bug]           The default control channel listened on the
                        wildcard adress, not the loopback as documented.
                        [RT #1975]
@@ -6,9 +11,6 @@
                        to be sent to syslog in addition to stderr.
                        [RT #1974]
 
-
-       --- 9.2.0rc9 released ---
-
 1078.  [bug]           We failed to correct bad tv_usec values in one case.
                        [RT #1966]
 
index ca308d162abed72584c2bd76ed5d0718a483f6f0..32c6d1ed538ab23c8cf4e6770e67b658ec12db66 100644 (file)
@@ -1,44 +1,86 @@
 /*
-%%% copyright-cmetz-97
-This software is Copyright 1997-1998 by Craig Metz, All Rights Reserved.
-The Inner Net License Version 2 applies to this software.
-You should have received a copy of the license with this software. If
-you didn't get a copy, you may request one from <license@inner.net>.
-
-*/
+ * Copyright (c) 2001 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
 
 #include <port_before.h>
 #include <netdb.h>
 #include <port_after.h>
 
+#ifdef DO_PTHREADS
+#include <pthread.h>
+#include <stdlib.h>
+#endif
+
+static const char *gai_errlist[] = {
+       "no error",
+       "address family not supported for name",/* EAI_ADDRFAMILY */
+       "temporary failure",                    /* EAI_AGAIN */
+       "invalid flags",                        /* EAI_BADFLAGS */
+       "permanent failure",                    /* EAI_FAIL */
+       "address family not supported",         /* EAI_FAMILY */
+       "memory failure",                       /* EAI_MEMORY */
+       "no address",                           /* EAI_NODATA */
+       "unknown name or service",              /* EAI_NONAME */
+       "service not supported for socktype",   /* EAI_SERVICE */
+       "socktype not supported",               /* EAI_SOCKTYPE */
+       "system failure",                       /* EAI_SYSTEM */
+       "bad hints",                            /* EAI_BADHINTS */
+       "bad protocol",                         /* EAI_PROTOCOL */
+
+       "unknown error"                         /* Must be last. */
+};
+
+static const int gai_nerr = (sizeof(gai_errlist)/sizeof(*gai_errlist));
+
+#define EAI_BUFSIZE 128
+
 const char *
-gai_strerror(int errnum) {
-       switch(errnum) {
-       case 0:
-               return "no error";
-       case EAI_BADFLAGS:
-               return "invalid value for ai_flags";
-       case EAI_NONAME:
-               return "name or service is not known";
-       case EAI_AGAIN:
-               return "temporary failure in name resolution";
-       case EAI_FAIL:
-               return "non-recoverable failure in name resolution";
-       case EAI_NODATA:
-               return "no address associated with name";
-       case EAI_FAMILY:
-               return "ai_family not supported";
-       case EAI_SOCKTYPE:
-               return "ai_socktype not supported";
-       case EAI_SERVICE:
-               return "service not supported for ai_socktype";
-       case EAI_ADDRFAMILY:
-               return "address family for name not supported";
-       case EAI_MEMORY:
-               return "memory allocation failure";
-       case EAI_SYSTEM:
-               return "system error";
-       default:
-               return "unknown error";
-       };
+gai_strerror(int ecode) {
+#ifndef DO_PTHREADS
+       static char buf[EAI_BUFSIZE];
+#else  DO_PTHREADS
+       static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+       static pthread_key_t key;
+       static int once = 0;
+       char *buf;
+#endif
+
+       if (ecode >= 0 && ecode < (gai_nerr - 1))
+               return (gai_errlist[ecode]);
+
+#ifdef DO_PTHREADS
+        if (!once) {
+                pthread_mutex_lock(&lock);
+                if (!once++)
+                        pthread_key_create(&key, free);
+                pthread_mutex_unlock(&lock);
+        }
+
+       buf = pthread_getspecific(key);
+        if (buf == NULL) {
+               buf = malloc(EAI_BUFSIZE);
+                if (buf == NULL)
+                        return ("unknown error");
+                pthread_setspecific(key, buf);
+        }
+#endif
+       /* 
+        * XXX This really should be snprintf(buf, EAI_BUFSIZE, ...).
+        * It is safe until message catalogs are used.
+        */
+       sprintf(buf, "%s: %d", gai_errlist[gai_nerr - 1], ecode);
+       return (buf);
 }