aboutsummaryrefslogtreecommitdiff
path: root/bfd/opncls.c
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2009-06-12 12:04:19 +0000
committerNick Clifton <nickc@redhat.com>2009-06-12 12:04:19 +0000
commit8c7d38e8f0eb20955214cca062ff6deec0c60db3 (patch)
treeba5f19f940491d60deaeb470c710299a4a062e4a /bfd/opncls.c
parentd3a44ec61fa6afe54544fca32485cc47921fe7dc (diff)
downloadgdb-8c7d38e8f0eb20955214cca062ff6deec0c60db3.zip
gdb-8c7d38e8f0eb20955214cca062ff6deec0c60db3.tar.gz
gdb-8c7d38e8f0eb20955214cca062ff6deec0c60db3.tar.bz2
* opncls.c (_maybe_make_executable): New function. Gives execute
permission to an executable bfd that was opened for writing provided that it is a regular file. Replaces common code found in... (bfd_close): here and ... (bfd_close_all_done): here.
Diffstat (limited to 'bfd/opncls.c')
-rw-r--r--bfd/opncls.c66
1 files changed, 30 insertions, 36 deletions
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 3add02f..6a4f319 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -629,6 +629,32 @@ bfd_openw (const char *filename, const char *target)
return nbfd;
}
+static inline void
+_maybe_make_executable (bfd * abfd)
+{
+ /* If the file was open for writing and is now executable,
+ make it so. */
+ if (abfd->direction == write_direction
+ && abfd->flags & EXEC_P)
+ {
+ struct stat buf;
+
+ if (stat (abfd->filename, &buf) == 0
+ /* Do not attempt to change non-regular files. This is
+ here especially for configure scripts and kernel builds
+ which run tests with "ld [...] -o /dev/null". */
+ && S_ISREG(buf.st_mode))
+ {
+ unsigned int mask = umask (0);
+
+ umask (mask);
+ chmod (abfd->filename,
+ (0777
+ & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
+ }
+ }
+}
+
/*
FUNCTION
@@ -684,24 +710,8 @@ bfd_close (bfd *abfd)
else
ret = TRUE;
- /* If the file was open for writing and is now executable,
- make it so. */
- if (ret
- && abfd->direction == write_direction
- && abfd->flags & EXEC_P)
- {
- struct stat buf;
-
- if (stat (abfd->filename, &buf) == 0)
- {
- unsigned int mask = umask (0);
-
- umask (mask);
- chmod (abfd->filename,
- (0777
- & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
- }
- }
+ if (ret)
+ _maybe_make_executable (abfd);
_bfd_delete_bfd (abfd);
@@ -737,24 +747,8 @@ bfd_close_all_done (bfd *abfd)
ret = bfd_cache_close (abfd);
- /* If the file was open for writing and is now executable,
- make it so. */
- if (ret
- && abfd->direction == write_direction
- && abfd->flags & EXEC_P)
- {
- struct stat buf;
-
- if (stat (abfd->filename, &buf) == 0)
- {
- unsigned int mask = umask (0);
-
- umask (mask);
- chmod (abfd->filename,
- (0777
- & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
- }
- }
+ if (ret)
+ _maybe_make_executable (abfd);
_bfd_delete_bfd (abfd);