mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.pposix: Remove fallocate
This commit is contained in:
parent
7b4ad0e694
commit
d6184b31a3
3 changed files with 3 additions and 62 deletions
|
@ -7,7 +7,7 @@
|
|||
--
|
||||
|
||||
|
||||
local want_pposix_version = "0.3.7";
|
||||
local want_pposix_version = "0.4.0";
|
||||
|
||||
local pposix = assert(require "util.pposix");
|
||||
if pposix._VERSION ~= want_pposix_version then
|
||||
|
|
|
@ -135,7 +135,7 @@ dependencies.log_warnings();
|
|||
-- Switch away from root and into the prosody user --
|
||||
local switched_user, current_uid;
|
||||
|
||||
local want_pposix_version = "0.3.7";
|
||||
local want_pposix_version = "0.4.0";
|
||||
local ok, pposix = pcall(require, "util.pposix");
|
||||
|
||||
if ok and pposix then
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue