util-src/pposix.c
changeset 6155 dc3497041aca
parent 6154 dfe88a0e18fd
child 6156 6b1aee6536e8
--- 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)
 	{