Merge 0.9->0.10
[prosody.git] / util-src / pposix.c
index c0d1f5a29e891484c7fc93139efc0876b9450e88..73e0d6e390e145be2d2080b67103462d99c56ab8 100644 (file)
@@ -36,7 +36,7 @@
 #include "lauxlib.h"
 
 #include <fcntl.h>
-#if defined(_GNU_SOURCE)
+#if defined(__linux__) && defined(_GNU_SOURCE)
 #include <linux/falloc.h>
 #endif
 
@@ -491,7 +491,7 @@ int string2resource(const char *s) {
        return -1;
 }
 
-int arg_to_rlimit(lua_State* L, int idx, rlim_t current) {
+unsigned long int arg_to_rlimit(lua_State* L, int idx, rlim_t current) {
        switch(lua_type(L, idx)) {
        case LUA_TSTRING:
                if(strcmp(lua_tostring(L, idx), "unlimited") == 0)
@@ -676,11 +676,13 @@ int lc_fallocate(lua_State* L)
 {
        off_t offset, len;
        FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE);
+       if (f == NULL)
+               luaL_error(L, "attempt to use a closed file");
 
        offset = luaL_checkinteger(L, 2);
        len = luaL_checkinteger(L, 3);
 
-#if defined(_GNU_SOURCE)
+#if defined(__linux__) && defined(_GNU_SOURCE)
        if(fallocate(fileno(f), FALLOC_FL_KEEP_SIZE, offset, len) == 0)
        {
                lua_pushboolean(L, 1);