summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/bfd/cache.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2000-05-12 23:15:20 +0000
committerobrien <obrien@FreeBSD.org>2000-05-12 23:15:20 +0000
commit2a9ea95d682586d2b0c31da28d82a73d786c7c0a (patch)
tree9d4ce42d357c391a11d77254b770908c02ecf672 /contrib/binutils/bfd/cache.c
parentbffe850874e72664f78cf171ab1c4339b9b63cab (diff)
downloadFreeBSD-src-2a9ea95d682586d2b0c31da28d82a73d786c7c0a.zip
FreeBSD-src-2a9ea95d682586d2b0c31da28d82a73d786c7c0a.tar.gz
Import of Binutils 2.10 snapshot.
Diffstat (limited to 'contrib/binutils/bfd/cache.c')
-rw-r--r--contrib/binutils/bfd/cache.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/contrib/binutils/bfd/cache.c b/contrib/binutils/bfd/cache.c
index b28de4b..ad3140e 100644
--- a/contrib/binutils/bfd/cache.c
+++ b/contrib/binutils/bfd/cache.c
@@ -285,10 +285,25 @@ bfd_open_file (abfd)
}
else
{
- /* Create the file. Unlink it first, for the convenience of
- operating systems which worry about overwriting running
- binaries. */
- unlink (abfd->filename);
+ /* Create the file.
+
+ Some operating systems won't let us overwrite a running
+ binary. For them, we want to unlink the file first.
+
+ However, gcc 2.95 will create temporary files using
+ O_EXCL and tight permissions to prevent other users from
+ substituting other .o files during the compilation. gcc
+ will then tell the assembler to use the newly created
+ file as an output file. If we unlink the file here, we
+ open a brief window when another user could still
+ substitute a file.
+
+ So we unlink the output file if and only if it has
+ non-zero size. */
+ struct stat s;
+
+ if (stat (abfd->filename, &s) == 0 && s.st_size != 0)
+ unlink (abfd->filename);
abfd->iostream = (PTR) fopen (abfd->filename, FOPEN_WB);
abfd->opened_once = true;
}
OpenPOWER on IntegriCloud