aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2001-08-22 21:51:48 +0000
committerCorinna Vinschen <corinna@vinschen.de>2001-08-22 21:51:48 +0000
commitcb19ccf4b5f516a404da2f90f5d12721d81c73e1 (patch)
treef913a1d7e04a23f5db1fd1326a003abcc224d47e /winsup
parent0a047e8f321216f24140ee18135bbe9ea4461f0a (diff)
downloadnewlib-cb19ccf4b5f516a404da2f90f5d12721d81c73e1.zip
newlib-cb19ccf4b5f516a404da2f90f5d12721d81c73e1.tar.gz
newlib-cb19ccf4b5f516a404da2f90f5d12721d81c73e1.tar.bz2
* 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')
-rw-r--r--winsup/cygwin/ChangeLog16
-rw-r--r--winsup/cygwin/net.cc128
-rw-r--r--winsup/cygwin/passwd.cc12
-rw-r--r--winsup/cygwin/thread.h6
4 files changed, 94 insertions, 68 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index ec406ed..fb69b18 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,19 @@
+Wed Aug 22 23:41:00 2001 Corinna Vinschen <corinna@vinschen.de>
+
+ * 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.
+
Wed Aug 22 13:41:09 2001 Christopher Faylor <cgf@cygnus.com>
* smallprint.c (console_printf): New function.
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 9f0db03..19063e9 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)
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index a1a5c33..f7b0853 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -376,36 +376,24 @@ getpwent (void)
extern "C" struct passwd *
getpwduid (uid_t)
{
- if (passwd_state <= initializing)
- read_etc_passwd ();
-
return NULL;
}
extern "C" void
setpwent (void)
{
- if (passwd_state <= initializing)
- read_etc_passwd ();
-
pw_pos = 0;
}
extern "C" void
endpwent (void)
{
- if (passwd_state <= initializing)
- read_etc_passwd ();
-
pw_pos = 0;
}
extern "C" int
setpassent ()
{
- if (passwd_state <= initializing)
- read_etc_passwd ();
-
return 0;
}
diff --git a/winsup/cygwin/thread.h b/winsup/cygwin/thread.h
index 34096c3..b871d34 100644
--- a/winsup/cygwin/thread.h
+++ b/winsup/cygwin/thread.h
@@ -94,6 +94,12 @@ struct _winsup_t
/* uinfo.cc */
char _username[UNLEN + 1];
+
+ /* net.cc */
+ char *_ntoa_buf;
+ struct protoent *_protoent_buf;
+ struct servent *_servent_buf;
+ struct hostent *_hostent_buf;
};