aboutsummaryrefslogtreecommitdiffstats
path: root/util-src
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-01-10 21:48:25 +0000
committerMatthew Wild <mwild1@gmail.com>2010-01-10 21:48:25 +0000
commit4558719f38c410d298d3b297f276ec4bf878a211 (patch)
tree8562bf4e76775815ee11fe8f0aa24d9608b0cfe2 /util-src
parentf2f2393a6a381d671fe9a889dea5b135ffebddab (diff)
downloadprosody-4558719f38c410d298d3b297f276ec4bf878a211.tar.gz
prosody-4558719f38c410d298d3b297f276ec4bf878a211.zip
util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
Diffstat (limited to 'util-src')
-rw-r--r--util-src/pposix.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/util-src/pposix.c b/util-src/pposix.c
index ae3e1bb8..b47faaaf 100644
--- a/util-src/pposix.c
+++ b/util-src/pposix.c
@@ -13,9 +13,10 @@
* POSIX support functions for Lua
*/
-#define MODULE_VERSION "0.3.1"
+#define MODULE_VERSION "0.3.2"
#include <stdlib.h>
+#include <math.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/resource.h>
@@ -358,6 +359,18 @@ int lc_setgid(lua_State* L)
return 2;
}
+int lc_umask(lua_State* L)
+{
+ char old_mode_string[7];
+ mode_t old_mode = umask(strtoul(luaL_checkstring(L, 1), NULL, 8));
+
+ snprintf(old_mode_string, sizeof(old_mode_string), "%03o", old_mode);
+ old_mode_string[sizeof(old_mode_string)-1] = 0;
+ lua_pushstring(L, old_mode_string);
+
+ return 1;
+}
+
/* Like POSIX's setrlimit()/getrlimit() API functions.
*
* Syntax:
@@ -506,6 +519,9 @@ int luaopen_util_pposix(lua_State *L)
lua_pushcfunction(L, lc_setgid);
lua_setfield(L, -2, "setgid");
+ lua_pushcfunction(L, lc_umask);
+ lua_setfield(L, -2, "umask");
+
lua_pushcfunction(L, lc_setrlimit);
lua_setfield(L, -2, "setrlimit");