aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-04-23 15:49:25 +0000
committerTom Tromey <tromey@redhat.com>2013-04-23 15:49:25 +0000
commit5d71132c29839d6c5593eaed39dfe8e8be5673b1 (patch)
tree190a6f5a12f681c57495741bb7b47cddb3334400
parent29f045bb482a412d4f410f368c333df2dc8c771e (diff)
downloadgdb-5d71132c29839d6c5593eaed39dfe8e8be5673b1.zip
gdb-5d71132c29839d6c5593eaed39dfe8e8be5673b1.tar.gz
gdb-5d71132c29839d6c5593eaed39dfe8e8be5673b1.tar.bz2
* common/filestuff.c: Check USE_WIN32API before including
sys/socket.h. (HAVE_F_GETFD): New define. (mark_cloexec): Check HAVE_F_GETFD. (gdb_open_cloexec): Change 'mode' to unsigned long. (gdb_socketpair_cloexec): Check HAVE_SOCKETPAIR. (gdb_pipe_cloexec): Check HAVE_PIPE. * common/filestuff.h (gdb_open_cloexec): Change 'mode' to unsigned long.
-rw-r--r--gdb/ChangeLog12
-rw-r--r--gdb/common/filestuff.c24
-rw-r--r--gdb/common/filestuff.h3
3 files changed, 35 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 911353d..228afcb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,15 @@
+2013-04-23 Tom Tromey <tromey@redhat.com>
+
+ * common/filestuff.c: Check USE_WIN32API before including
+ sys/socket.h.
+ (HAVE_F_GETFD): New define.
+ (mark_cloexec): Check HAVE_F_GETFD.
+ (gdb_open_cloexec): Change 'mode' to unsigned long.
+ (gdb_socketpair_cloexec): Check HAVE_SOCKETPAIR.
+ (gdb_pipe_cloexec): Check HAVE_PIPE.
+ * common/filestuff.h (gdb_open_cloexec): Change 'mode' to unsigned
+ long.
+
2013-04-23 Hui Zhu <hui@codesourcery.com>
PR gdb/15293
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index 2cc1c4d..2984c43 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -28,10 +28,18 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
-#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
+#ifdef USE_WIN32API
+#include <winsock2.h>
+#include <windows.h>
+#else
+#include <sys/socket.h>
+/* Define HAVE_F_GETFD if we plan to use F_GETFD. */
+#define HAVE_F_GETFD F_GETFD
+#endif
+
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif /* HAVE_SYS_RESOURCE_H */
@@ -215,6 +223,7 @@ static int trust_o_cloexec;
static void
mark_cloexec (int fd)
{
+#ifdef HAVE_F_GETFD
int old = fcntl (fd, F_GETFD, 0);
if (old != -1)
@@ -229,6 +238,7 @@ mark_cloexec (int fd)
trust_o_cloexec = -1;
}
}
+#endif /* HAVE_F_GETFD */
}
/* Depending on TRUST_O_CLOEXEC, mark FD as close-on-exec. */
@@ -254,7 +264,7 @@ socket_mark_cloexec (int fd)
/* See filestuff.h. */
int
-gdb_open_cloexec (const char *filename, int flags, mode_t mode)
+gdb_open_cloexec (const char *filename, int flags, unsigned long mode)
{
int fd = open (filename, flags | O_CLOEXEC, mode);
@@ -303,6 +313,7 @@ gdb_fopen_cloexec (const char *filename, const char *opentype)
int
gdb_socketpair_cloexec (int namespace, int style, int protocol, int filedes[2])
{
+#ifdef HAVE_SOCKETPAIR
int result = socketpair (namespace, style | SOCK_CLOEXEC, protocol, filedes);
if (result != -1)
@@ -312,6 +323,9 @@ gdb_socketpair_cloexec (int namespace, int style, int protocol, int filedes[2])
}
return result;
+#else
+ gdb_assert_not_reached (_("socketpair not available on this host"));
+#endif
}
/* See filestuff.h. */
@@ -342,13 +356,17 @@ gdb_pipe_cloexec (int filedes[2])
maybe_mark_cloexec (filedes[1]);
}
#else
+#ifdef HAVE_PIPE
result = pipe (filedes);
if (result != -1)
{
mark_cloexec (filedes[0]);
mark_cloexec (filedes[1]);
}
-#endif
+#else /* HAVE_PIPE */
+ gdb_assert_not_reached (_("pipe not available on this host"));
+#endif /* HAVE_PIPE */
+#endif /* HAVE_PIPE2 */
return result;
}
diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
index 747bff2..0db33f0 100644
--- a/gdb/common/filestuff.h
+++ b/gdb/common/filestuff.h
@@ -33,7 +33,8 @@ extern void close_most_fds (void);
/* Like 'open', but ensures that the returned file descriptor has the
close-on-exec flag set. */
-extern int gdb_open_cloexec (const char *filename, int flags, mode_t mode);
+extern int gdb_open_cloexec (const char *filename, int flags,
+ /* mode_t */ unsigned long mode);
/* Like 'fopen', but ensures that the returned file descriptor has the
close-on-exec flag set. */