From 07b1c3dbd96ff68bcb9017d01feb6063b94d4bf1 Mon Sep 17 00:00:00 2001 From: Holger Berger Date: Fri, 19 Mar 2021 15:38:54 -0700 Subject: [PATCH] Fix call to system fallocate to handle errno correctly. 2021-03-19 Holger Berger gold/ PR gold/26541 * output.cc (gold_fallocate): Use errno when calling system fallocate. --- gold/ChangeLog | 5 +++++ gold/output.cc | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gold/ChangeLog b/gold/ChangeLog index 2d4e6092a27..4aec6d4683b 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,8 @@ +2021-03-19 Holger Berger + + PR gold/26541 + * output.cc (gold_fallocate): Use errno when calling system fallocate. + 2021-03-19 Cary Coutant PR gold/26585 diff --git a/gold/output.cc b/gold/output.cc index b7505ffd72c..afdba06753e 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -141,12 +141,14 @@ gold_fallocate(int o, off_t offset, off_t len) #ifdef HAVE_FALLOCATE { + errno = 0; int err = ::fallocate(o, 0, offset, len); - if (err != EINVAL && err != ENOSYS && err != EOPNOTSUPP) - return err; + if (err < 0 && errno != EINVAL && errno != ENOSYS && errno != EOPNOTSUPP) + return errno; } #endif // defined(HAVE_FALLOCATE) + errno = 0; if (::ftruncate(o, offset + len) < 0) return errno; return 0; -- 2.30.2