diff options
author | Ian Lance Taylor <ian@airs.com> | 2000-04-03 19:19:11 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 2000-04-03 19:19:11 +0000 |
commit | 9e422a2e278b0a18a2553810d1c8ec20e7c2d758 (patch) | |
tree | 0a82e6bf6c4a7dca2ca377c95aa1d7077a2bc6f5 /bfd/cache.c | |
parent | d61e6540a1b6130942636db0d2216c52e0625276 (diff) | |
download | gdb-9e422a2e278b0a18a2553810d1c8ec20e7c2d758.zip gdb-9e422a2e278b0a18a2553810d1c8ec20e7c2d758.tar.gz gdb-9e422a2e278b0a18a2553810d1c8ec20e7c2d758.tar.bz2 |
2000-04-03 H.J. Lu <hjl@gnu.org>
* cache.c (bfd_open_file): Unlink the output file only if
it has none zero size.
Diffstat (limited to 'bfd/cache.c')
-rw-r--r-- | bfd/cache.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/bfd/cache.c b/bfd/cache.c index b28de4b..ad3140e 100644 --- a/bfd/cache.c +++ b/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; } |