diff options
author | Tom Tromey <tromey@redhat.com> | 2008-11-06 14:10:46 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2008-11-06 14:10:46 +0000 |
commit | 428b207a69c493f7e324b2fea3043bd7d76bcd2c (patch) | |
tree | 99d8f0f75bcda877a5dd2ad020a7c1dc555d75a8 | |
parent | efd20d3a427f2e39e616fd4eb902dbd573480c20 (diff) | |
download | binutils-gdb-428b207a69c493f7e324b2fea3043bd7d76bcd2c.tar.gz |
* configure, config.in: Rebuild.
* configure.in: Check for fileno.
* bfdio.c (close_on_exec): New function.
(real_fopen): Use it.
(FD_CLOEXEC): New define.
-rw-r--r-- | bfd/ChangeLog | 8 | ||||
-rw-r--r-- | bfd/bfdio.c | 25 | ||||
-rw-r--r-- | bfd/config.in | 3 | ||||
-rwxr-xr-x | bfd/configure | 3 | ||||
-rw-r--r-- | bfd/configure.in | 2 |
5 files changed, 37 insertions, 4 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 0504b473b40..54b69d0b91d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +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. diff --git a/bfd/bfdio.c b/bfd/bfdio.c index d8aa1de9992..cb06453e016 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 } diff --git a/bfd/config.in b/bfd/config.in index f15e4ff3785..d1797aedfa1 100644 --- a/bfd/config.in +++ b/bfd/config.in @@ -78,6 +78,9 @@ /* 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 diff --git a/bfd/configure b/bfd/configure index 84ba0f6a338..5cd7e776c47 100755 --- a/bfd/configure +++ b/bfd/configure @@ -17553,7 +17553,8 @@ fi -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 diff --git a/bfd/configure.in b/bfd/configure.in index 72cefbcda45..bcc461552b9 100644 --- a/bfd/configure.in +++ b/bfd/configure.in @@ -179,7 +179,7 @@ GCC_HEADER_STDINT(bfd_stdint.h) AC_HEADER_TIME AC_HEADER_DIRENT ACX_HEADER_STRING -AC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf fdopen getuid getgid) +AC_CHECK_FUNCS(fcntl getpagesize setitimer sysconf fdopen getuid getgid fileno) AC_CHECK_FUNCS(strtoull) AC_CHECK_DECLS(basename) |