diff options
author | Colin Walters <walters@verbum.org> | 2016-08-03 11:00:08 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2016-08-04 14:42:59 -0400 |
commit | 5ac0d702d70b00887f9329e47f4d5653e994531a (patch) | |
tree | 8f071139e85c163fa30c796eec787a2d098ab469 /glnx-fdio.c | |
parent | c2ba4d879956436c1349acb0aeafd6f885276c67 (diff) | |
download | libglnx-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.c | 13 |
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) |