From 5ac0d702d70b00887f9329e47f4d5653e994531a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 3 Aug 2016 11:00:08 -0400 Subject: fdio: Only invoke fallocate() for sizes > 0 In some cases we want to replace with zero size, and `posix_fallocate()` is documented to return `EINVAL` in this case. Making this change since I noticed it elsewhere. --- glnx-fdio.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'glnx-fdio.c') diff --git a/glnx-fdio.c b/glnx-fdio.c index 8200660..19144da 100644 --- a/glnx-fdio.c +++ b/glnx-fdio.c @@ -926,12 +926,15 @@ glnx_file_replace_contents_with_perms_at (int dfd, len = strlen ((char*)buf); /* Note that posix_fallocate does *not* set errno but returns it. */ - r = posix_fallocate (fd, 0, len); - if (r != 0) + if (len > 0) { - errno = r; - glnx_set_error_from_errno (error); - return FALSE; + r = posix_fallocate (fd, 0, len); + if (r != 0) + { + errno = r; + glnx_set_error_from_errno (error); + return FALSE; + } } if ((r = glnx_loop_write (fd, buf, len)) != 0) -- cgit v1.2.1