libotutil: Fix two bugs in usage of posix_fallocate()

* It's invalid to call it with a size of 0, so don't do that.

* posix_* apparently don't set errno.  So capture the return value and
  use that.
This commit is contained in:
Colin Walters committed 2014-04-29 07:40:25 -04:00
1 parent 22ab7b3e79
commit 5346e0615b
1 file changed
+7 -3
+7 -3
View File
@@ -308,10 +308,14 @@ ot_gfile_replace_contents_fsync (GFile *path,
instream = g_memory_input_stream_new_from_bytes (contents); instream = g_memory_input_stream_new_from_bytes (contents);
if (posix_fallocate (fd, 0, g_bytes_get_size (contents)) != 0) if (g_bytes_get_size (contents) > 0)
{ {
ot_util_set_error_from_errno (error, errno); int r = posix_fallocate (fd, 0, g_bytes_get_size (contents));
goto out; if (r != 0)
{
ot_util_set_error_from_errno (error, r);
goto out;
}
} }
if (g_output_stream_splice (stream, instream, 0, if (g_output_stream_splice (stream, instream, 0,