+2008-11-06 Tom Tromey <tromey@redhat.com>
+
+ * configure, config.in: Rebuild.
+ * configure.in: Check for fileno.
+ * bfdio.c (close_on_exec): New function.
+ (real_fopen): Use it.
+ (FD_CLOEXEC): New define.
+
2008-11-06 Tristan Gingold <gingold@adacore.com>
* mach-o.h (BFD_MACH_O_NO_SECT): Add; reorders the macros.
#define S_IXOTH 0001 /* Execute by others. */
#endif
+#ifndef FD_CLOEXEC
+#define FD_CLOEXEC 1
+#endif
+
file_ptr
real_ftell (FILE *file)
{
#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
}
/* Define to 1 if you have the `fdopen' function. */
#undef HAVE_FDOPEN
+/* Define to 1 if you have the `fileno' function. */
+#undef HAVE_FILENO
+
/* Define to 1 if you have the `fopen64' function. */
#undef HAVE_FOPEN64
-for ac_func in fcntl getpagesize setitimer sysconf fdopen getuid getgid
+
+for ac_func in fcntl getpagesize setitimer sysconf fdopen getuid getgid fileno
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5