Software /
code /
prosody
Comparison
util-src/pposix.c @ 2438:819ba949c7bc
util.pposix: Add pposix.umask(), bump version to 0.3.2 (and do the same in mod_posix)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 10 Jan 2010 21:48:25 +0000 |
parent | 2437:b1ba2473fd91 |
child | 2441:d72078946a16 |
comparison
equal
deleted
inserted
replaced
2437:b1ba2473fd91 | 2438:819ba949c7bc |
---|---|
11 /* | 11 /* |
12 * pposix.c | 12 * pposix.c |
13 * POSIX support functions for Lua | 13 * POSIX support functions for Lua |
14 */ | 14 */ |
15 | 15 |
16 #define MODULE_VERSION "0.3.1" | 16 #define MODULE_VERSION "0.3.2" |
17 | 17 |
18 #include <stdlib.h> | 18 #include <stdlib.h> |
19 #include <math.h> | |
19 #include <unistd.h> | 20 #include <unistd.h> |
20 #include <libgen.h> | 21 #include <libgen.h> |
21 #include <sys/resource.h> | 22 #include <sys/resource.h> |
22 #include <sys/types.h> | 23 #include <sys/types.h> |
23 #include <sys/stat.h> | 24 #include <sys/stat.h> |
356 lua_pushboolean(L, 0); | 357 lua_pushboolean(L, 0); |
357 lua_pushstring(L, "invalid-gid"); | 358 lua_pushstring(L, "invalid-gid"); |
358 return 2; | 359 return 2; |
359 } | 360 } |
360 | 361 |
362 int lc_umask(lua_State* L) | |
363 { | |
364 char old_mode_string[7]; | |
365 mode_t old_mode = umask(strtoul(luaL_checkstring(L, 1), NULL, 8)); | |
366 | |
367 snprintf(old_mode_string, sizeof(old_mode_string), "%03o", old_mode); | |
368 old_mode_string[sizeof(old_mode_string)-1] = 0; | |
369 lua_pushstring(L, old_mode_string); | |
370 | |
371 return 1; | |
372 } | |
373 | |
361 /* Like POSIX's setrlimit()/getrlimit() API functions. | 374 /* Like POSIX's setrlimit()/getrlimit() API functions. |
362 * | 375 * |
363 * Syntax: | 376 * Syntax: |
364 * pposix.setrlimit( resource, soft limit, hard limit) | 377 * pposix.setrlimit( resource, soft limit, hard limit) |
365 * | 378 * |
504 lua_pushcfunction(L, lc_setuid); | 517 lua_pushcfunction(L, lc_setuid); |
505 lua_setfield(L, -2, "setuid"); | 518 lua_setfield(L, -2, "setuid"); |
506 lua_pushcfunction(L, lc_setgid); | 519 lua_pushcfunction(L, lc_setgid); |
507 lua_setfield(L, -2, "setgid"); | 520 lua_setfield(L, -2, "setgid"); |
508 | 521 |
522 lua_pushcfunction(L, lc_umask); | |
523 lua_setfield(L, -2, "umask"); | |
524 | |
509 lua_pushcfunction(L, lc_setrlimit); | 525 lua_pushcfunction(L, lc_setrlimit); |
510 lua_setfield(L, -2, "setrlimit"); | 526 lua_setfield(L, -2, "setrlimit"); |
511 | 527 |
512 lua_pushcfunction(L, lc_getrlimit); | 528 lua_pushcfunction(L, lc_getrlimit); |
513 lua_setfield(L, -2, "getrlimit"); | 529 lua_setfield(L, -2, "getrlimit"); |