summaryrefslogtreecommitdiff
path: root/glnx-fdio.c
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2016-08-03 11:00:08 -0400
committerColin Walters <walters@verbum.org>2016-08-04 14:42:59 -0400
commit5ac0d702d70b00887f9329e47f4d5653e994531a (patch)
tree8f071139e85c163fa30c796eec787a2d098ab469 /glnx-fdio.c
parentc2ba4d879956436c1349acb0aeafd6f885276c67 (diff)
downloadlibglnx-5ac0d702d70b00887f9329e47f4d5653e994531a.tar.gz
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.
Diffstat (limited to 'glnx-fdio.c')
-rw-r--r--glnx-fdio.c13
1 files changed, 8 insertions, 5 deletions
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)