aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygserver/transport_sockets.cc
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2004-09-15 10:17:53 +0000
committerCorinna Vinschen <corinna@vinschen.de>2004-09-15 10:17:53 +0000
commit1dcd520bb878cfd02e72f31b9e2d8ccdd3073a2c (patch)
tree94b87d56b4ff157a24e01fd570a906987f1ba51c /winsup/cygserver/transport_sockets.cc
parentb103e0d73285adeb8dc4dfa58568dacf2927742e (diff)
downloadnewlib-1dcd520bb878cfd02e72f31b9e2d8ccdd3073a2c.zip
newlib-1dcd520bb878cfd02e72f31b9e2d8ccdd3073a2c.tar.gz
newlib-1dcd520bb878cfd02e72f31b9e2d8ccdd3073a2c.tar.bz2
Fix copyright throughout.
Eliminate use of _impure_ptr outside Cygwin. * bsd_helper.cc: Include errno.h instead of cygerrno.h. * bsd_mutex.cc : Ditto. * client.cc: Ditto. * cygserver.cc: Ditto. * process.cc: Don't build functions inside Cygwin. Don't include cygerrno.h. Don't set errno. * transport_pipes.cc (SET_ERRNO): New define. Use througout. * transport_sockets.cc (SET_ERRNO): Ditto. (GET_ERRNO): Ditto.
Diffstat (limited to 'winsup/cygserver/transport_sockets.cc')
-rw-r--r--winsup/cygserver/transport_sockets.cc54
1 files changed, 31 insertions, 23 deletions
diff --git a/winsup/cygserver/transport_sockets.cc b/winsup/cygserver/transport_sockets.cc
index f3668f6..d89e343 100644
--- a/winsup/cygserver/transport_sockets.cc
+++ b/winsup/cygserver/transport_sockets.cc
@@ -1,6 +1,6 @@
/* transport_sockets.cc
- Copyright 2001, 2002 Red Hat Inc.
+ Copyright 2001, 2002, 2003, 2004 Red Hat Inc.
Written by Robert Collins <rbtcollins@hotmail.com>
@@ -22,13 +22,21 @@ details. */
#include <sys/stat.h>
#include <assert.h>
-#include <errno.h>
#include <stdio.h>
#include <unistd.h>
+#include "cygerrno.h"
#include "transport.h"
#include "transport_sockets.h"
+#ifdef __INSIDE_CYGWIN__
+#define SET_ERRNO(err) set_errno (err)
+#define GET_ERRNO() get_errno ()
+#else
+#define SET_ERRNO(err) errno = (err)
+#define GET_ERRNO() (errno)
+#endif
+
/* to allow this to link into cygwin and the .dll, a little magic is needed. */
#ifndef __OUTSIDE_CYGWIN__
@@ -99,10 +107,10 @@ transport_layer_sockets::listen ()
if (stat (_addr.sun_path, &sbuf) == -1)
{
- if (errno != ENOENT)
+ if (GET_ERRNO () != ENOENT)
{
system_printf ("cannot access socket file `%s': %s",
- _addr.sun_path, strerror (errno));
+ _addr.sun_path, strerror (GET_ERRNO ()));
return -1;
}
}
@@ -115,7 +123,7 @@ transport_layer_sockets::listen ()
if (newfd == -1)
{
system_printf ("failed to create UNIX domain socket: %s",
- strerror (errno));
+ strerror (GET_ERRNO ()));
return -1;
}
@@ -133,7 +141,7 @@ transport_layer_sockets::listen ()
if (unlink (_addr.sun_path) == -1)
{
system_printf ("failed to remove `%s': %s",
- _addr.sun_path, strerror (errno));
+ _addr.sun_path, strerror (GET_ERRNO ()));
(void) ::close (newfd);
return -1;
}
@@ -150,17 +158,17 @@ transport_layer_sockets::listen ()
if (_fd == -1)
{
system_printf ("failed to create UNIX domain socket: %s",
- strerror (errno));
+ strerror (GET_ERRNO ()));
return -1;
}
if (cygwin_bind (_fd, (struct sockaddr *) &_addr, _addr_len) == -1)
{
- const int saved_errno = errno;
+ const int saved_errno = GET_ERRNO ();
close ();
- errno = saved_errno;
+ SET_ERRNO (saved_errno);
system_printf ("failed to bind UNIX domain socket `%s': %s",
- _addr.sun_path, strerror (errno));
+ _addr.sun_path, strerror (GET_ERRNO ()));
return -1;
}
@@ -168,11 +176,11 @@ transport_layer_sockets::listen ()
if (cygwin_listen (_fd, SOMAXCONN) == -1)
{
- const int saved_errno = errno;
+ const int saved_errno = GET_ERRNO ();
close ();
- errno = saved_errno;
+ SET_ERRNO (saved_errno);
system_printf ("failed to listen on UNIX domain socket `%s': %s",
- _addr.sun_path, strerror (errno));
+ _addr.sun_path, strerror (GET_ERRNO ()));
return -1;
}
@@ -198,8 +206,8 @@ transport_layer_sockets::accept (bool *const recoverable)
if (accept_fd == -1)
{
- system_printf ("failed to accept connection: %s", strerror (errno));
- switch (errno)
+ system_printf ("failed to accept connection: %s", strerror (GET_ERRNO ()));
+ switch (GET_ERRNO ())
{
case ECONNABORTED:
case EINTR:
@@ -276,7 +284,7 @@ transport_layer_sockets::read (void *const buf, const size_t buf_len)
if (res != -1)
{
if (res == 0)
- errno = EIO; // FIXME?
+ SET_ERRNO (EIO); // FIXME?
res = buf_len - read_buf_len;
}
@@ -284,7 +292,7 @@ transport_layer_sockets::read (void *const buf, const size_t buf_len)
if (res != static_cast<ssize_t> (buf_len))
debug_printf ("%d = read (buf = %p, len = %u) [this = %p, fd = %d]: %s",
res, buf, buf_len, this, _fd,
- (res == -1 ? strerror (errno) : "EOF"));
+ (res == -1 ? strerror (GET_ERRNO ()) : "EOF"));
else
{
// verbose: debug_printf ("%d = read (buf = %p, len = %u) [this = %p, fd = %d]",
@@ -322,7 +330,7 @@ transport_layer_sockets::write (void *const buf, const size_t buf_len)
if (res != -1)
{
if (res == 0)
- errno = EIO; // FIXME?
+ SET_ERRNO (EIO); // FIXME?
res = buf_len - write_buf_len;
}
@@ -330,7 +338,7 @@ transport_layer_sockets::write (void *const buf, const size_t buf_len)
if (res != static_cast<ssize_t> (buf_len))
debug_printf ("%d = write (buf = %p, len = %u) [this = %p, fd = %d]: %s",
res, buf, buf_len, this, _fd,
- (res == -1 ? strerror (errno) : "EOF"));
+ (res == -1 ? strerror (GET_ERRNO ()) : "EOF"));
else
{
// verbose: debug_printf ("%d = write (buf = %p, len = %u) [this = %p, fd = %d]",
@@ -358,7 +366,7 @@ transport_layer_sockets::connect ()
if (_fd == -1)
{
system_printf ("failed to create UNIX domain socket: %s",
- strerror (errno));
+ strerror (GET_ERRNO ()));
return -1;
}
@@ -369,9 +377,9 @@ transport_layer_sockets::connect ()
return 0;
}
- if (!assume_cygserver || errno != ECONNREFUSED)
+ if (!assume_cygserver || GET_ERRNO () != ECONNREFUSED)
{
- debug_printf ("failed to connect to server: %s", strerror (errno));
+ debug_printf ("failed to connect to server: %s", strerror (GET_ERRNO ()));
(void) ::close (_fd);
_fd = -1;
return -1;
@@ -382,6 +390,6 @@ transport_layer_sockets::connect ()
Sleep (0); // Give the server a chance.
}
- debug_printf ("failed to connect to server: %s", strerror (errno));
+ debug_printf ("failed to connect to server: %s", strerror (GET_ERRNO ()));
return -1;
}