projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
util.pposix: Add mkdir(path)
[prosody.git]
/
util-src
/
pposix.c
diff --git
a/util-src/pposix.c
b/util-src/pposix.c
index b47faaafe414aedc57f8669b479fa57753fac44b..9627dab782ff190e5a93666bece697497df4032e 100644
(file)
--- a/
util-src/pposix.c
+++ b/
util-src/pposix.c
@@
-371,6
+371,21
@@
int lc_umask(lua_State* L)
return 1;
}
return 1;
}
+int lc_mkdir(lua_State* L)
+{
+ int ret = mkdir(luaL_checkstring(L, 1), S_IRUSR | S_IWUSR | S_IXUSR
+ | S_IRGRP | S_IWGRP | S_IXGRP
+ | S_IROTH | S_IXOTH); /* mode 775 */
+
+ lua_pushboolean(L, ret==0);
+ if(ret)
+ {
+ lua_pushstring(L, strerror(errno));
+ return 2;
+ }
+ return 1;
+}
+
/* Like POSIX's setrlimit()/getrlimit() API functions.
*
* Syntax:
/* Like POSIX's setrlimit()/getrlimit() API functions.
*
* Syntax:
@@
-486,47
+501,34
@@
int lc_abort(lua_State* L)
int luaopen_util_pposix(lua_State *L)
{
int luaopen_util_pposix(lua_State *L)
{
- lua_newtable(L);
-
- lua_pushcfunction(L, lc_abort);
- lua_setfield(L, -2, "abort");
-
- lua_pushcfunction(L, lc_daemonize);
- lua_setfield(L, -2, "daemonize");
-
- lua_pushcfunction(L, lc_syslog_open);
- lua_setfield(L, -2, "syslog_open");
+ luaL_Reg exports[] = {
+ { "abort", lc_abort },
- lua_pushcfunction(L, lc_syslog_close);
- lua_setfield(L, -2, "syslog_close");
+ { "daemonize", lc_daemonize },
- lua_pushcfunction(L, lc_syslog_log);
- lua_setfield(L, -2, "syslog_log");
+ { "syslog_open", lc_syslog_open },
+ { "syslog_close", lc_syslog_close },
+ { "syslog_log", lc_syslog_log },
+ { "syslog_setminlevel", lc_syslog_setmask },
- lua_pushcfunction(L, lc_syslog_setmask);
- lua_setfield(L, -2, "syslog_setminlevel");
+ { "getpid", lc_getpid },
+ { "getuid", lc_getuid },
+ { "getgid", lc_getgid },
- lua_pushcfunction(L, lc_getpid);
- lua_setfield(L, -2, "getpid");
+ { "setuid", lc_setuid },
+ { "setgid", lc_setgid },
- lua_pushcfunction(L, lc_getuid);
- lua_setfield(L, -2, "getuid");
- lua_pushcfunction(L, lc_getgid);
- lua_setfield(L, -2, "getgid");
+ { "umask", lc_umask },
- lua_pushcfunction(L, lc_setuid);
- lua_setfield(L, -2, "setuid");
- lua_pushcfunction(L, lc_setgid);
- lua_setfield(L, -2, "setgid");
+ { "mkdir", lc_mkdir },
- lua_pushcfunction(L, lc_umask);
- lua_setfield(L, -2, "umask");
+ { "setrlimit", lc_setrlimit },
+ { "getrlimit", lc_getrlimit },
- lua_pushcfunction(L, lc_setrlimit);
-
lua_setfield(L, -2, "setrlimit")
;
+ { NULL, NULL }
+
}
;
- lua_pushcfunction(L, lc_getrlimit);
- lua_setfield(L, -2, "getrlimit");
+ luaL_register(L, "pposix", exports);
lua_pushliteral(L, "pposix");
lua_setfield(L, -2, "_NAME");
lua_pushliteral(L, "pposix");
lua_setfield(L, -2, "_NAME");