Software /
code /
prosody
Comparison
util-src/pposix.c @ 3481:72d3c8029178
util.pposix: Add pposix.uname(), bump version
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 31 Aug 2010 15:14:39 +0100 |
parent | 3471:482275e38224 |
child | 3482:e1a4f7b15caf |
comparison
equal
deleted
inserted
replaced
3480:97831dfe7f72 | 3481:72d3c8029178 |
---|---|
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.4" | 16 #define MODULE_VERSION "0.3.5" |
17 | 17 |
18 #include <stdlib.h> | 18 #include <stdlib.h> |
19 #include <math.h> | 19 #include <math.h> |
20 #include <unistd.h> | 20 #include <unistd.h> |
21 #include <libgen.h> | 21 #include <libgen.h> |
22 #include <sys/resource.h> | 22 #include <sys/resource.h> |
23 #include <sys/types.h> | 23 #include <sys/types.h> |
24 #include <sys/stat.h> | 24 #include <sys/stat.h> |
25 #include <sys/utsname.h> | |
25 #include <fcntl.h> | 26 #include <fcntl.h> |
26 | 27 |
27 #include <syslog.h> | 28 #include <syslog.h> |
28 #include <pwd.h> | 29 #include <pwd.h> |
29 #include <grp.h> | 30 #include <grp.h> |
551 { | 552 { |
552 abort(); | 553 abort(); |
553 return 0; | 554 return 0; |
554 } | 555 } |
555 | 556 |
557 int lc_uname(lua_State* L) | |
558 { | |
559 struct utsname uname_info; | |
560 if(uname(&uname_info) != 0) | |
561 { | |
562 lua_pushstring(L, strerror(errno)); | |
563 return 2; | |
564 } | |
565 lua_newtable(L); | |
566 lua_pushstring(L, uname_info.sysname); | |
567 lua_setfield(L, -2, "sysname"); | |
568 lua_pushstring(L, uname_info.nodename); | |
569 lua_setfield(L, -2, "nodename"); | |
570 lua_pushstring(L, uname_info.release); | |
571 lua_setfield(L, -2, "release"); | |
572 lua_pushstring(L, uname_info.version); | |
573 lua_setfield(L, -2, "version"); | |
574 lua_pushstring(L, uname_info.machine); | |
575 lua_setfield(L, -2, "machine"); | |
576 return 1; | |
577 } | |
578 | |
556 /* Register functions */ | 579 /* Register functions */ |
557 | 580 |
558 int luaopen_util_pposix(lua_State *L) | 581 int luaopen_util_pposix(lua_State *L) |
559 { | 582 { |
560 luaL_Reg exports[] = { | 583 luaL_Reg exports[] = { |
580 { "mkdir", lc_mkdir }, | 603 { "mkdir", lc_mkdir }, |
581 | 604 |
582 { "setrlimit", lc_setrlimit }, | 605 { "setrlimit", lc_setrlimit }, |
583 { "getrlimit", lc_getrlimit }, | 606 { "getrlimit", lc_getrlimit }, |
584 | 607 |
608 { "uname", lc_uname }, | |
609 | |
585 { NULL, NULL } | 610 { NULL, NULL } |
586 }; | 611 }; |
587 | 612 |
588 luaL_register(L, "pposix", exports); | 613 luaL_register(L, "pposix", exports); |
589 | 614 |