diff options
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luasocket/src/timeout.c')
-rw-r--r-- | Build/source/texk/web2c/luatexdir/luasocket/src/timeout.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/src/timeout.c b/Build/source/texk/web2c/luatexdir/luasocket/src/timeout.c index c1df1021811..c7354b52f38 100644 --- a/Build/source/texk/web2c/luatexdir/luasocket/src/timeout.c +++ b/Build/source/texk/web2c/luatexdir/luasocket/src/timeout.c @@ -1,10 +1,10 @@ /*=========================================================================*\ * Timeout management functions * LuaSocket toolkit -* -* RCS ID: $Id: timeout.c,v 1.30 2005/10/07 04:40:59 diego Exp $ \*=========================================================================*/ #include <stdio.h> +#include <limits.h> +#include <float.h> #include "lua.h" #include "lauxlib.h" @@ -33,7 +33,7 @@ static int timeout_lua_gettime(lua_State *L); static int timeout_lua_sleep(lua_State *L); -static luaL_reg func[] = { +static luaL_Reg func[] = { { "gettime", timeout_lua_gettime }, { "sleep", timeout_lua_sleep }, { NULL, NULL } @@ -187,13 +187,23 @@ static int timeout_lua_gettime(lua_State *L) /*-------------------------------------------------------------------------*\ * Sleep for n seconds. \*-------------------------------------------------------------------------*/ +#ifdef _WIN32 int timeout_lua_sleep(lua_State *L) { double n = luaL_checknumber(L, 1); -#ifdef _WIN32 - Sleep((int)(n*1000)); + if (n < 0.0) n = 0.0; + if (n < DBL_MAX/1000.0) n *= 1000.0; + if (n > INT_MAX) n = INT_MAX; + Sleep((int)n); + return 0; +} #else +int timeout_lua_sleep(lua_State *L) +{ + double n = luaL_checknumber(L, 1); struct timespec t, r; + if (n < 0.0) n = 0.0; + if (n > INT_MAX) n = INT_MAX; t.tv_sec = (int) n; n -= t.tv_sec; t.tv_nsec = (int) (n * 1000000000); @@ -202,6 +212,6 @@ int timeout_lua_sleep(lua_State *L) t.tv_sec = r.tv_sec; t.tv_nsec = r.tv_nsec; } -#endif return 0; } +#endif |