Software /
code /
prosody
Diff
util-src/pposix.c @ 8012:e898c8fda986
util.pposix: Remove fallocate
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 28 Feb 2017 13:26:05 +0100 |
parent | 8010:49feb0da29e1 |
child | 9028:d4c2a3060e7e |
child | 9278:8f9e18d4fe50 |
line wrap: on
line diff
--- a/util-src/pposix.c Tue Feb 28 11:33:43 2017 +0100 +++ b/util-src/pposix.c Tue Feb 28 13:26:05 2017 +0100 @@ -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 @@ } #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 @@ { "meminfo", lc_meminfo }, #endif - { "fallocate", lc_fallocate }, { "atomic_append", lc_atomic_append }, { NULL, NULL }