aboutsummaryrefslogtreecommitdiff
path: root/bfd/bfdio.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2008-11-06 14:10:46 +0000
committerTom Tromey <tromey@redhat.com>2008-11-06 14:10:46 +0000
commit428b207a69c493f7e324b2fea3043bd7d76bcd2c (patch)
tree99d8f0f75bcda877a5dd2ad020a7c1dc555d75a8 /bfd/bfdio.c
parentefd20d3a427f2e39e616fd4eb902dbd573480c20 (diff)
downloadgdb-428b207a69c493f7e324b2fea3043bd7d76bcd2c.zip
gdb-428b207a69c493f7e324b2fea3043bd7d76bcd2c.tar.gz
gdb-428b207a69c493f7e324b2fea3043bd7d76bcd2c.tar.bz2
* configure, config.in: Rebuild.
* configure.in: Check for fileno. * bfdio.c (close_on_exec): New function. (real_fopen): Use it. (FD_CLOEXEC): New define.
Diffstat (limited to 'bfd/bfdio.c')
-rw-r--r--bfd/bfdio.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index d8aa1de..cb06453 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -38,6 +38,10 @@
#define S_IXOTH 0001 /* Execute by others. */
#endif
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
file_ptr
real_ftell (FILE *file)
{
@@ -62,13 +66,30 @@ real_fseek (FILE *file, file_ptr offset, int whence)
#endif
}
+/* Mark FILE as close-on-exec. Return FILE. FILE may be NULL, in
+ which case nothing is done. */
+static FILE *
+close_on_exec (FILE *file)
+{
+#if defined (HAVE_FILENO) && defined (F_GETFD)
+ if (file)
+ {
+ int fd = fileno (file);
+ int old = fcntl (fd, F_GETFD, 0);
+ if (old >= 0)
+ fcntl (fd, F_SETFD, old | FD_CLOEXEC);
+ }
+#endif
+ return file;
+}
+
FILE *
real_fopen (const char *filename, const char *modes)
{
#if defined (HAVE_FOPEN64)
- return fopen64 (filename, modes);
+ return close_on_exec (fopen64 (filename, modes));
#else
- return fopen (filename, modes);
+ return close_on_exec (fopen (filename, modes));
#endif
}