From 7d9688b79355c0e0d91ce1f6d1e5189ed8121797 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sat, 14 Oct 2000 08:55:44 +0000 Subject: [PATCH] * cygwin.din: Add symbol hstrerror. * net.cc: Change meaning of member `s' of struct host_errmap. (set_host_errno): Fix error in loop condition. (hstrerror): Ditto. (herror): Add appropriate functionality. * include/netdb.h: Add declaration of hstrerror. * include/cygwin/version.h: Bump CYGWIN_VERSION_API_MINOR to 29. --- winsup/cygwin/cygwin.din | 1 + winsup/cygwin/include/cygwin/version.h | 3 +- winsup/cygwin/include/netdb.h | 1 + winsup/cygwin/net.cc | 60 ++++++++++++++++++++++---- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din index 31675836b..2399c8bf3 100644 --- a/winsup/cygwin/cygwin.din +++ b/winsup/cygwin/cygwin.din @@ -925,6 +925,7 @@ _ntohs = ntohs accept = cygwin_accept bind = cygwin_bind connect = cygwin_connect +hstrerror = cygwin_hstrerror herror = cygwin_herror inet_addr = cygwin_inet_addr inet_network = cygwin_inet_network diff --git a/winsup/cygwin/include/cygwin/version.h b/winsup/cygwin/include/cygwin/version.h index c261c64fb..ff440b955 100644 --- a/winsup/cygwin/include/cygwin/version.h +++ b/winsup/cygwin/include/cygwin/version.h @@ -118,10 +118,11 @@ details. */ 26: CW_GET_CYGDRIVE_PREFIXES addition to external.cc 27: CW_GETPINFO_FULL addition to external.cc 28: Accidentally bumped by cgf + 29: Export hstrerror */ #define CYGWIN_VERSION_API_MAJOR 0 -#define CYGWIN_VERSION_API_MINOR 28 +#define CYGWIN_VERSION_API_MINOR 29 /* There is also a compatibity version number associated with the shared memory regions. It is incremented when incompatible diff --git a/winsup/cygwin/include/netdb.h b/winsup/cygwin/include/netdb.h index d1acc5e0a..7e4cc000d 100644 --- a/winsup/cygwin/include/netdb.h +++ b/winsup/cygwin/include/netdb.h @@ -151,6 +151,7 @@ struct servent *getservent (void); struct rpcent *getrpcent (void); struct rpcent *getrpcbyname (const char *); struct rpcent *getrpcbynumber (int); +const char *hstrerror (int); void herror (const char *); void sethostent (int); void setnetent (int); diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 8f4220637..c6d88f613 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -252,12 +252,16 @@ __set_winsock_errno (const char *fn, int ln) } } +/* + * Since the member `s' isn't used for debug output we can use it + * for the error text returned by herror and hstrerror. + */ static struct tl host_errmap[] = { - {WSAHOST_NOT_FOUND, "WSAHOST_NOT_FOUND", HOST_NOT_FOUND}, - {WSATRY_AGAIN, "WSATRY_AGAIN", TRY_AGAIN}, - {WSANO_RECOVERY, "WSANO_RECOVERY", NO_RECOVERY}, - {WSANO_DATA, "WSANO_DATA", NO_DATA}, + {WSAHOST_NOT_FOUND, "Unknown host", HOST_NOT_FOUND}, + {WSATRY_AGAIN, "Host name lookup failure", TRY_AGAIN}, + {WSANO_RECOVERY, "Unknown server error", NO_RECOVERY}, + {WSANO_DATA, "No address associated with name", NO_DATA}, {0, NULL, 0} }; @@ -268,7 +272,7 @@ set_host_errno () int i; int why = WSAGetLastError (); - for (i = 0; i < host_errmap[i].w != 0; ++i) + for (i = 0; host_errmap[i].w != 0; ++i) if (why == host_errmap[i].w) break; @@ -884,11 +888,49 @@ cygwin_shutdown (int fd, int how) return res; } -/* exported as herror: standards? */ -extern "C" void -cygwin_herror (const char *) +/* exported as hstrerror: BSD 4.3 */ +extern "C" const char * +cygwin_hstrerror (int err) { - debug_printf ("********%d*************", __LINE__); + int i; + + for (i = 0; host_errmap[i].e != 0; ++i) + if (err == host_errmap[i].e) + break; + + return host_errmap[i].s; +} + +/* exported as herror: BSD 4.3 */ +extern "C" void +cygwin_herror (const char *s) +{ + if (fdtab.not_open (2)) + return; + + if (s) + { + write (2, s, strlen (s)); + write (2, ": ", 2); + } + + const char *h_errstr = cygwin_hstrerror (h_errno); + + if (!h_errstr) + switch (h_errno) + { + case NETDB_INTERNAL: + h_errstr = "Resolver internal error"; + break; + case NETDB_SUCCESS: + h_errstr = "Resolver error 0 (no error)"; + break; + default: + h_errstr = "Unknown resolver error"; + break; + } + write (2, h_errstr, strlen (h_errstr)); + write (2, "\n", 1); } /* exported as getpeername: standards? */