diff options
Diffstat (limited to 'util-src')
-rw-r--r-- | util-src/pposix.c | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c index a68aa89d..e70a9d7f 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -13,7 +13,7 @@ * POSIX support functions for Lua */ -#define MODULE_VERSION "0.3.7" +#define MODULE_VERSION "0.4.0" #if defined(__linux__) @@ -730,64 +730,6 @@ int lc_meminfo(lua_State *L) { } #endif -/* File handle extraction blatantly stolen from - * https://github.com/rrthomas/luaposix/blob/master/lposix.c#L631 - * */ - -int lc_fallocate(lua_State *L) { - int ret; - off_t offset, len; - FILE *f = *(FILE **) luaL_checkudata(L, 1, LUA_FILEHANDLE); - - if(f == NULL) { - return luaL_error(L, "attempt to use a closed file"); - } - - offset = luaL_checkinteger(L, 2); - len = luaL_checkinteger(L, 3); - -#if defined(__linux__) - 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) { - lua_pushnil(L); - lua_pushstring(L, strerror(errno)); - return 2; - } - -#endif - - ret = posix_fallocate(fileno(f), offset, len); - - if(ret == 0) { - lua_pushboolean(L, 1); - return 1; - } else { - lua_pushnil(L); - lua_pushstring(L, strerror(ret)); - - /* posix_fallocate() can leave a bunch of NULs at the end, so we cut that - * this assumes that offset == length of the file */ - if(ftruncate(fileno(f), offset) != 0) { - lua_pushstring(L, strerror(errno)); - return 3; - } - - return 2; - } -} - /* * Append some data to a file handle * Attempt to allocate space first @@ -889,7 +831,6 @@ int luaopen_util_pposix(lua_State *L) { { "meminfo", lc_meminfo }, #endif - { "fallocate", lc_fallocate }, { "atomic_append", lc_atomic_append }, { NULL, NULL } |