truncate is not available on every host. Opening the file with
O_WRONLY | O_TRUNC has the same effect here, and like truncate it does
not create the file if it does not exist. The driver already uses open
the same way elsewhere.
Bootstrapped and regression-tested on x86_64-pc-linux-gnu
(default languages, --disable-multilib), with no new regressions
relative to the unmodified baseline.
Also tested with a non-GCC, EDG-based host compiler (GNU extensions
disabled) on a non-glibc platform, where the patch resolves a build
failure.
gcc/ChangeLog:
* gcc.cc (driver::final_actions): Truncate the -truncate file with
open and O_TRUNC instead of truncate.
Signed-off-by: Shiva <[email protected]>
---
gcc/gcc.cc | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index 973a3402330..e6b206ee5ab 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -9459,9 +9459,13 @@ driver::final_actions () const
delete_temp_files ();
if (totruncate_file != NULL && !seen_error ())
- /* Truncate file specified by -truncate.
- Used by lto-wrapper to reduce temporary disk-space usage. */
- truncate(totruncate_file, 0);
+ {
+ /* Truncate file specified by -truncate.
+ Used by lto-wrapper to reduce temporary disk-space usage. */
+ int fd = open (totruncate_file, O_WRONLY | O_TRUNC);
+ if (fd >= 0)
+ close (fd);
+ }
if (print_help_list)
{