diff options
author | Kim Alvefur <zash@zash.se> | 2012-07-03 15:43:46 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2012-07-03 15:43:46 +0200 |
commit | 0c7777aeb6c1b668e2b9e1fddf036dcb27f6db46 (patch) | |
tree | 522648199eb50618acea07af833c0a432c6b06f8 /util-src | |
parent | 9d379a1dae9a6b46a4e11a13ccdcece4f8c60679 (diff) | |
download | prosody-0c7777aeb6c1b668e2b9e1fddf036dcb27f6db46.tar.gz prosody-0c7777aeb6c1b668e2b9e1fddf036dcb27f6db46.zip |
util.pposix: Add setenv()
Diffstat (limited to 'util-src')
-rw-r--r-- | util-src/pposix.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c index dae48390..a5a89d55 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -581,6 +581,37 @@ int lc_uname(lua_State* L) return 1; } +int lc_setenv(lua_State* L) +{ + const char *var = luaL_checkstring(L, 1); + const char *value; + + /* If the second argument is nil or nothing, unset the var */ + if(lua_isnoneornil(L, 2)) + { + if(unsetenv(var) != 0) + { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } + lua_pushboolean(L, 1); + return 1; + } + + value = luaL_checkstring(L, 2); + + if(setenv(var, value, 1) != 0) + { + lua_pushnil(L); + lua_pushstring(L, strerror(errno)); + return 2; + } + + lua_pushboolean(L, 1); + return 1; +} + /* Register functions */ int luaopen_util_pposix(lua_State *L) @@ -612,6 +643,8 @@ int luaopen_util_pposix(lua_State *L) { "uname", lc_uname }, + { "setenv", lc_setenv }, + { NULL, NULL } }; |