mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 09:49:05 +00:00
Updated to Lua 5.1.3 (Bug fix release)
Updated stdnse to include tobinary, toocal, and tohex functions. Minor optimizations to listop.lua
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: loslib.c,v 1.17 2006/01/27 13:54:31 roberto Exp $
|
||||
** $Id: loslib.c,v 1.19.1.3 2008/01/18 16:38:18 roberto Exp $
|
||||
** Standard Operating System library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -28,10 +28,7 @@ static int os_pushresult (lua_State *L, int i, const char *filename) {
|
||||
}
|
||||
else {
|
||||
lua_pushnil(L);
|
||||
if (filename)
|
||||
lua_pushfstring(L, "%s: %s", filename, strerror(en));
|
||||
else
|
||||
lua_pushfstring(L, "%s", strerror(en));
|
||||
lua_pushfstring(L, "%s: %s", filename, strerror(en));
|
||||
lua_pushinteger(L, en);
|
||||
return 3;
|
||||
}
|
||||
@@ -126,8 +123,7 @@ static int getfield (lua_State *L, const char *key, int d) {
|
||||
|
||||
static int os_date (lua_State *L) {
|
||||
const char *s = luaL_optstring(L, 1, "%c");
|
||||
time_t t = lua_isnoneornil(L, 2) ? time(NULL) :
|
||||
(time_t)luaL_checknumber(L, 2);
|
||||
time_t t = luaL_opt(L, (time_t)luaL_checknumber, 2, time(NULL));
|
||||
struct tm *stm;
|
||||
if (*s == '!') { /* UTC? */
|
||||
stm = gmtime(&t);
|
||||
@@ -150,11 +146,22 @@ static int os_date (lua_State *L) {
|
||||
setboolfield(L, "isdst", stm->tm_isdst);
|
||||
}
|
||||
else {
|
||||
char b[256];
|
||||
if (strftime(b, sizeof(b), s, stm))
|
||||
lua_pushstring(L, b);
|
||||
else
|
||||
return luaL_error(L, LUA_QL("date") " format too long");
|
||||
char cc[3];
|
||||
luaL_Buffer b;
|
||||
cc[0] = '%'; cc[2] = '\0';
|
||||
luaL_buffinit(L, &b);
|
||||
for (; *s; s++) {
|
||||
if (*s != '%' || *(s + 1) == '\0') /* no conversion specifier? */
|
||||
luaL_addchar(&b, *s);
|
||||
else {
|
||||
size_t reslen;
|
||||
char buff[200]; /* should be big enough for any conversion result */
|
||||
cc[1] = *(++s);
|
||||
reslen = strftime(buff, sizeof(buff), cc, stm);
|
||||
luaL_addlstring(&b, buff, reslen);
|
||||
}
|
||||
}
|
||||
luaL_pushresult(&b);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -199,9 +206,8 @@ static int os_setlocale (lua_State *L) {
|
||||
LC_NUMERIC, LC_TIME};
|
||||
static const char *const catnames[] = {"all", "collate", "ctype", "monetary",
|
||||
"numeric", "time", NULL};
|
||||
const char *l = lua_tostring(L, 1);
|
||||
const char *l = luaL_optstring(L, 1, NULL);
|
||||
int op = luaL_checkoption(L, 2, "all", catnames);
|
||||
luaL_argcheck(L, l || lua_isnoneornil(L, 1), 1, "string expected");
|
||||
lua_pushstring(L, setlocale(cat[op], l));
|
||||
return 1;
|
||||
}
|
||||
@@ -209,7 +215,6 @@ static int os_setlocale (lua_State *L) {
|
||||
|
||||
static int os_exit (lua_State *L) {
|
||||
exit(luaL_optint(L, 1, EXIT_SUCCESS));
|
||||
return 0; /* to avoid warnings */
|
||||
}
|
||||
|
||||
static const luaL_Reg syslib[] = {
|
||||
|
||||
Reference in New Issue
Block a user