Changeset

6155:dc3497041aca

util.pposix: Fix error reporting from really old Linux fallocate() that did not use errno for some reason (thanks pro)
author Kim Alvefur <zash@zash.se>
date Fri, 25 Apr 2014 02:41:55 +0200
parents 6154:dfe88a0e18fd
children 6156:6b1aee6536e8 6166:46cb87d531a7
files util-src/pposix.c
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/util-src/pposix.c	Fri Apr 25 00:36:01 2014 +0200
+++ b/util-src/pposix.c	Fri Apr 25 02:41:55 2014 +0200
@@ -674,11 +674,15 @@
 	len = luaL_checkinteger(L, 3);
 
 #if defined(__linux__) && defined(_GNU_SOURCE)
-	if(fallocate(fileno(f), FALLOC_FL_KEEP_SIZE, offset, len) == 0)
+	errno = 0;
+	ret = fallocate(fileno(f), FALLOC_FL_KEEP_SIZE, offset, len);
+	if(ret == 0)
 	{
 		lua_pushboolean(L, 1);
 		return 1;
 	}
+	/* Some old versions of Linux apparently use the return value instead of errno */
+	if(errno == 0) errno = ret;
 
 	if(errno != ENOSYS && errno != EOPNOTSUPP)
 	{