util-src/pposix.c
changeset 4946 2975c7008ccd
parent 4934 5a6a85719b7b
child 4950 02e5e9fa37b8
equal deleted inserted replaced
4944:72a2eec4204a 4946:2975c7008ccd
    31 
    31 
    32 #include <string.h>
    32 #include <string.h>
    33 #include <errno.h>
    33 #include <errno.h>
    34 #include "lua.h"
    34 #include "lua.h"
    35 #include "lauxlib.h"
    35 #include "lauxlib.h"
       
    36 
       
    37 #if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO))
       
    38 	#include <malloc.h>
       
    39 	#define WITH_MALLINFO
       
    40 #endif
    36 
    41 
    37 /* Daemonization support */
    42 /* Daemonization support */
    38 
    43 
    39 static int lc_daemonize(lua_State *L)
    44 static int lc_daemonize(lua_State *L)
    40 {
    45 {
   610 
   615 
   611 	lua_pushboolean(L, 1);
   616 	lua_pushboolean(L, 1);
   612 	return 1;
   617 	return 1;
   613 }
   618 }
   614 
   619 
       
   620 #ifdef WITH_MALLINFO
       
   621 int lc_meminfo(lua_State* L)
       
   622 {
       
   623 	struct mallinfo info = mallinfo();
       
   624 	lua_newtable(L);
       
   625 	lua_pushinteger(L, info.arena);
       
   626 	lua_setfield(L, -2, "allocated");
       
   627 	lua_pushinteger(L, info.hblkhd);
       
   628 	lua_setfield(L, -2, "allocated_mmap");
       
   629 	lua_pushinteger(L, info.uordblks);
       
   630 	lua_setfield(L, -2, "used");
       
   631 	lua_pushinteger(L, info.fordblks);
       
   632 	lua_setfield(L, -2, "unused");
       
   633 	lua_pushinteger(L, info.keepcost);
       
   634 	lua_setfield(L, -2, "returnable");
       
   635 	return 1;
       
   636 }
       
   637 #endif
       
   638 
   615 /* Register functions */
   639 /* Register functions */
   616 
   640 
   617 int luaopen_util_pposix(lua_State *L)
   641 int luaopen_util_pposix(lua_State *L)
   618 {
   642 {
   619 	luaL_Reg exports[] = {
   643 	luaL_Reg exports[] = {
   643 
   667 
   644 		{ "uname", lc_uname },
   668 		{ "uname", lc_uname },
   645 
   669 
   646 		{ "setenv", lc_setenv },
   670 		{ "setenv", lc_setenv },
   647 
   671 
       
   672 #ifdef WITH_MALLINFO
       
   673 		{ "meminfo", lc_meminfo },
       
   674 #endif
       
   675 
   648 		{ NULL, NULL }
   676 		{ NULL, NULL }
   649 	};
   677 	};
   650 
   678 
   651 	luaL_register(L, "pposix",  exports);
   679 	luaL_register(L, "pposix",  exports);
   652 
   680