Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2001-08-23 01:51:48 +0400
committerCorinna Vinschen <corinna@vinschen.de>2001-08-23 01:51:48 +0400
commitcb19ccf4b5f516a404da2f90f5d12721d81c73e1 (patch)
treef913a1d7e04a23f5db1fd1326a003abcc224d47e /winsup/cygwin/net.cc
parent0a047e8f321216f24140ee18135bbe9ea4461f0a (diff)
* net.cc (cygwin_inet_ntoa): Rearrange previous patch to use
thread local buffer space when compiled thread safe. (cygwin_getprotobyname): Ditto. (cygwin_getprotobynumber): Ditto. (cygwin_getservbyname): Ditto. (cygwin_getservbyport): Ditto. (cygwin_gethostbyname): Ditto. (cygwin_gethostbyaddr): Ditto. Move near to cygwin_gethostbyname. * thread.h (struct _winsup_t): Add pointers for above used buffer space. * passwd.cc (getpwduid): Remove initializing passwd. (setpwent): Ditto. (endpwent): Ditto. (setpassent): Ditto.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r--winsup/cygwin/net.cc128
1 files changed, 72 insertions, 56 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 9f0db0310..19063e9e8 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -182,17 +182,21 @@ dump_protoent (struct protoent *p)
extern "C" char *
cygwin_inet_ntoa (struct in_addr in)
{
- static char *buf = NULL;
+#ifdef _MT_SAFE
+#define ntoa_buf _reent_winsup ()->_ntoa_buf
+#else
+ static char *ntoa_buf = NULL;
+#endif
char *res = inet_ntoa (in);
- if (buf)
+ if (ntoa_buf)
{
- free (buf);
- buf = NULL;
+ free (ntoa_buf);
+ ntoa_buf = NULL;
}
if (res)
- buf = strdup (res);
- return buf;
+ ntoa_buf = strdup (res);
+ return ntoa_buf;
}
/* exported as inet_addr: BSD 4.3 */
@@ -446,32 +450,36 @@ out:
return NULL;
}
+#ifdef _MT_SAFE
+#define protoent_buf _reent_winsup ()->_protoent_buf
+#else
+ static struct protoent *protoent_buf = NULL;
+#endif
+
/* exported as getprotobyname: standards? */
extern "C" struct protoent *
cygwin_getprotobyname (const char *p)
{
- static struct protoent *res = NULL;
- free_protoent_ptr (res);
- res = dup_protoent_ptr (getprotobyname (p));
- if (!res)
+ free_protoent_ptr (protoent_buf);
+ protoent_buf = dup_protoent_ptr (getprotobyname (p));
+ if (!protoent_buf)
set_winsock_errno ();
- dump_protoent (res);
- return res;
+ dump_protoent (protoent_buf);
+ return protoent_buf;
}
/* exported as getprotobynumber: standards? */
extern "C" struct protoent *
cygwin_getprotobynumber (int number)
{
- static struct protoent *res = NULL;
- free_protoent_ptr (res);
- res = dup_protoent_ptr (getprotobynumber (number));
- if (!res)
+ free_protoent_ptr (protoent_buf);
+ protoent_buf = dup_protoent_ptr (getprotobynumber (number));
+ if (!protoent_buf)
set_winsock_errno ();
- dump_protoent (res);
- return res;
+ dump_protoent (protoent_buf);
+ return protoent_buf;
}
fhandler_socket *
@@ -927,32 +935,36 @@ out:
return NULL;
}
+#ifdef _MT_SAFE
+#define servent_buf _reent_winsup ()->_servent_buf
+#else
+ static struct servent *servent_buf = NULL;
+#endif
+
/* exported as getservbyname: standards? */
extern "C" struct servent *
cygwin_getservbyname (const char *name, const char *proto)
{
- static struct servent *p = NULL;
- free_servent_ptr (p);
- p = dup_servent_ptr (getservbyname (name, proto));
- if (!p)
+ free_servent_ptr (servent_buf);
+ servent_buf = dup_servent_ptr (getservbyname (name, proto));
+ if (!servent_buf)
set_winsock_errno ();
- syscall_printf ("%x = getservbyname (%s, %s)", p, name, proto);
- return p;
+ syscall_printf ("%x = getservbyname (%s, %s)", servent_buf, name, proto);
+ return servent_buf;
}
/* exported as getservbyport: standards? */
extern "C" struct servent *
cygwin_getservbyport (int port, const char *proto)
{
- static struct servent *p = NULL;
- free_servent_ptr (p);
- p = dup_servent_ptr (getservbyport (port, proto));
- if (!p)
+ free_servent_ptr (servent_buf);
+ servent_buf = dup_servent_ptr (getservbyport (port, proto));
+ if (!servent_buf)
set_winsock_errno ();
- syscall_printf ("%x = getservbyport (%d, %s)", p, port, proto);
- return p;
+ syscall_printf ("%x = getservbyport (%d, %s)", servent_buf, port, proto);
+ return servent_buf;
}
extern "C" int
@@ -1021,6 +1033,12 @@ out:
return NULL;
}
+#ifdef _MT_SAFE
+#define hostent_buf _reent_winsup ()->_hostent_buf
+#else
+ static struct hostent *hostent_buf = NULL;
+#endif
+
/* exported as gethostbyname: standards? */
extern "C" struct hostent *
cygwin_gethostbyname (const char *name)
@@ -1048,20 +1066,38 @@ cygwin_gethostbyname (const char *name)
return &tmp;
}
- static struct hostent *ptr = NULL;
- free_hostent_ptr (ptr);
- ptr = dup_hostent_ptr (gethostbyname (name));
- if (!ptr)
+ free_hostent_ptr (hostent_buf);
+ hostent_buf = dup_hostent_ptr (gethostbyname (name));
+ if (!hostent_buf)
{
set_winsock_errno ();
set_host_errno ();
}
else
{
- debug_printf ("h_name %s", ptr->h_name);
+ debug_printf ("h_name %s", hostent_buf->h_name);
h_errno = 0;
}
- return ptr;
+ return hostent_buf;
+}
+
+/* exported as gethostbyaddr: standards? */
+extern "C" struct hostent *
+cygwin_gethostbyaddr (const char *addr, int len, int type)
+{
+ free_hostent_ptr (hostent_buf);
+ hostent_buf = dup_hostent_ptr (gethostbyaddr (addr, len, type));
+ if (!hostent_buf)
+ {
+ set_winsock_errno ();
+ set_host_errno ();
+ }
+ else
+ {
+ debug_printf ("h_name %s", hostent_buf->h_name);
+ h_errno = 0;
+ }
+ return hostent_buf;
}
/* exported as accept: standards? */
@@ -1260,26 +1296,6 @@ cygwin_getsockname (int fd, struct sockaddr *addr, int *namelen)
return res;
}
-/* exported as gethostbyaddr: standards? */
-extern "C" struct hostent *
-cygwin_gethostbyaddr (const char *addr, int len, int type)
-{
- static struct hostent *ptr = NULL;
- free_hostent_ptr (ptr);
- ptr = dup_hostent_ptr (gethostbyaddr (addr, len, type));
- if (!ptr)
- {
- set_winsock_errno ();
- set_host_errno ();
- }
- else
- {
- debug_printf ("h_name %s", ptr->h_name);
- h_errno = 0;
- }
- return ptr;
-}
-
/* exported as listen: standards? */
extern "C" int
cygwin_listen (int fd, int backlog)