Optimize 'string-hash'.
[bpt/guile.git] / libguile / net_db.c
index eb0c4c3..d7a12c5 100644 (file)
@@ -1,6 +1,7 @@
 /* "net_db.c" network database support
- * Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2006, 2009, 2010 Free Software Foundation, Inc.
- * 
+ * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2006, 2009,
+ *   2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
  * as published by the Free Software Foundation; either version 3 of
 #include <verify.h>
 #include <errno.h>
 
-#include "libguile/_scm.h"
-#include "libguile/feature.h"
-#include "libguile/strings.h"
-#include "libguile/vectors.h"
-#include "libguile/dynwind.h"
-
-#include "libguile/validate.h"
-#include "libguile/net_db.h"
-#include "libguile/socket.h"
-
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
 
 #include <sys/types.h>
 
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#else
 #include <sys/socket.h>
 #include <netdb.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#endif
 
-#ifdef __MINGW32__
-#include "win32-socket.h"
-#endif
+#include "libguile/_scm.h"
+#include "libguile/feature.h"
+#include "libguile/strings.h"
+#include "libguile/vectors.h"
+#include "libguile/dynwind.h"
 
-#if !defined (HAVE_H_ERRNO) && !defined (__MINGW32__) && !defined (__CYGWIN__)
-/* h_errno not found in netdb.h, maybe this will help.  */
-extern int h_errno;
-#endif
+#include "libguile/validate.h"
+#include "libguile/net_db.h"
+#include "libguile/socket.h"
+
+
+#if defined (HAVE_H_ERRNO)
+/* Only wrap gethostbyname / gethostbyaddr if h_errno is available.  */
 
-#if defined HAVE_HSTRERROR && !HAVE_DECL_HSTRERROR     \
-  && !defined __MINGW32__ && !defined __CYGWIN__
+#if defined HAVE_HSTRERROR && !HAVE_DECL_HSTRERROR
 /* Some OSes, such as Tru64 5.1b, lack a declaration for hstrerror(3).  */
 extern const char *hstrerror (int);
 #endif
 
-/* NetBSD 5.0 lacks the following flags.  */
-#ifndef AI_ALL
-# define AI_ALL 0
-#endif
-#ifndef AI_V4MAPPED
-# define AI_V4MAPPED 0
-#endif
-#ifndef AI_ADDRCONFIG
-# define AI_ADDRCONFIG 0
-#endif
-
-\f
-
 SCM_SYMBOL (scm_host_not_found_key, "host-not-found");
 SCM_SYMBOL (scm_try_again_key, "try-again");
 SCM_SYMBOL (scm_no_recovery_key, "no-recovery");
@@ -214,6 +192,8 @@ SCM_DEFINE (scm_gethost, "gethost", 0, 1, 0,
 }
 #undef FUNC_NAME
 
+#endif /* HAVE_H_ERRNO */
+
 
 /* In all subsequent getMUMBLE functions, when we're called with no
    arguments, we're supposed to traverse the tables entry by entry.
@@ -277,7 +257,7 @@ SCM_DEFINE (scm_getnet, "getnet", 0, 1, 0,
 #undef FUNC_NAME
 #endif
 
-#if defined (HAVE_GETPROTOENT) || defined (__MINGW32__)
+#if defined (HAVE_GETPROTOENT)
 SCM_DEFINE (scm_getproto, "getproto", 0, 1, 0, 
             (SCM protocol),
            "@deffnx {Scheme Procedure} getprotobyname name\n"
@@ -328,7 +308,7 @@ SCM_DEFINE (scm_getproto, "getproto", 0, 1, 0,
 #undef FUNC_NAME
 #endif
 
-#if defined (HAVE_GETSERVENT) || defined (__MINGW32__)
+#if defined (HAVE_GETSERVENT)
 static SCM
 scm_return_entry (struct servent *entry)
 {
@@ -430,7 +410,7 @@ SCM_DEFINE (scm_setnet, "setnet", 0, 1, 0,
 #undef FUNC_NAME
 #endif
 
-#if defined (HAVE_SETPROTOENT) && defined (HAVE_ENDPROTOENT) || defined (__MINGW32__)
+#if defined (HAVE_SETPROTOENT) && defined (HAVE_ENDPROTOENT)
 SCM_DEFINE (scm_setproto, "setproto", 0, 1, 0, 
             (SCM stayopen),
            "If @var{stayopen} is omitted, this is equivalent to @code{endprotoent}.\n"
@@ -446,7 +426,7 @@ SCM_DEFINE (scm_setproto, "setproto", 0, 1, 0,
 #undef FUNC_NAME
 #endif
 
-#if defined (HAVE_SETSERVENT) && defined (HAVE_ENDSERVENT) || defined (__MINGW32__)
+#if defined (HAVE_SETSERVENT) && defined (HAVE_ENDSERVENT)
 SCM_DEFINE (scm_setserv, "setserv", 0, 1, 0, 
             (SCM stayopen),
            "If @var{stayopen} is omitted, this is equivalent to @code{endservent}.\n"
@@ -468,7 +448,7 @@ SCM_DEFINE (scm_setserv, "setserv", 0, 1, 0,
 SCM_SYMBOL (sym_getaddrinfo_error, "getaddrinfo-error");
 
 /* Make sure the `AI_*' flags can be stored as INUMs.  */
-verify (SCM_I_INUM (SCM_I_MAKINUM (AI_ALL)) == AI_ALL);
+verify (AI_ALL < SCM_MOST_POSITIVE_FIXNUM);
 
 /* Valid values for the `ai_flags' to `struct addrinfo'.  */
 SCM_VARIABLE_INIT (sym_ai_passive, "AI_PASSIVE",
@@ -601,13 +581,24 @@ SCM_DEFINE (scm_getaddrinfo, "getaddrinfo", 1, 5, 0,
            "@item EAI_NONAME\n"
            "Either @var{name} does not resolve for the supplied parameters, "
            "or neither @var{name} nor @var{service} were supplied.\n\n"
+
+           /* See `sysdeps/posix/getaddrinfo.c' in the GNU libc, and
+              <http://www.opensource.apple.com/source/Libinfo/Libinfo-324.1/lookup.subproj/netdb.h>,
+              for details on EAI_NODATA.  */
+           "@item EAI_NODATA\n"
+           "This non-POSIX error code can be returned on some systems (GNU "
+           "and Darwin, at least), for example when @var{name} is known "
+           "but requests that were made turned out no data.  Error handling\n"
+           "code should be prepared to handle it when it is defined.\n\n"
            "@item EAI_SERVICE\n"
            "@var{service} was not recognized for the specified socket type.\n\n"
            "@item EAI_SOCKTYPE\n"
            "@var{hint_socktype} was not recognized.\n\n"
            "@item EAI_SYSTEM\n"
-           "A system error occurred; the error code can be found in "
-           "@code{errno}.\n"
+           "A system error occurred.  In C, the error code can be found in "
+           "@code{errno}; this value is not accessible from Scheme, but in\n"
+           "practice it provides little information about the actual error "
+           "cause.\n\n"          /* see <http://bugs.gnu.org/13958>. */
            "@end table\n"
            "\n"
            "Users are encouraged to read the "
@@ -683,7 +674,7 @@ SCM_DEFINE (scm_getaddrinfo, "getaddrinfo", 1, 5, 0,
 #undef FUNC_NAME
 
 /* Make sure the `EAI_*' flags can be stored as INUMs.  */
-verify (SCM_I_INUM (SCM_I_MAKINUM (EAI_BADFLAGS)) == EAI_BADFLAGS);
+verify (EAI_BADFLAGS < SCM_MOST_POSITIVE_FIXNUM);
 
 /* Error codes returned by `getaddrinfo'.  */
 SCM_VARIABLE_INIT (sym_eai_badflags, "EAI_BADFLAGS",