From: Holger Berger Date: Fri, 19 Mar 2021 22:38:54 +0000 (-0700) Subject: Fix call to system fallocate to handle errno correctly. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=07b1c3dbd96ff68bcb9017d01feb6063b94d4bf1;p=binutils-gdb.git 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. --- 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;