aboutsummaryrefslogtreecommitdiffstats
path: root/util-src
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-07-05 17:40:12 +0100
committerMatthew Wild <mwild1@gmail.com>2012-07-05 17:40:12 +0100
commitd7fbc07ca4b77809e07fc47e60f4ca87a7e9f997 (patch)
treed14b44262cee1dc74af32fbaa4658385b9552152 /util-src
parentbb7fd8bb306ea2d2893bb7c5bc460ec2f9886687 (diff)
parent02dc79e546ce19f54b858c102943ee6d80eec584 (diff)
downloadprosody-d7fbc07ca4b77809e07fc47e60f4ca87a7e9f997.tar.gz
prosody-d7fbc07ca4b77809e07fc47e60f4ca87a7e9f997.zip
Merge 0.9->trunk
Diffstat (limited to 'util-src')
-rw-r--r--util-src/pposix.c33
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 }
};