From f4bd17eab2667962090fc8a918b553badad671bc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 10 Jan 2014 19:53:11 -0800 Subject: * configure (lang_flags): Let us switch from using _XOPEN_SOURCE=2 to _POSIX_C_SOURCE=199309L and _BSD_SOURCE. In the .exe suffix test, try harder to redirect ls's output. Test for fork stuff now needs evidently; does not necessarily pid_t, even though it defines functions that return and accept pid_t! The timegm test no longer needs _SVID_SOURCE since _BSD_SOURCE covers it, and so we end up not using _SVID_SOURCE any more. New tests for usleep and nanosleep. The test for setenv is not conditional on timegm failing. * eval.c: Include and conditionally . (usleep_wrap): New function. (eval_init): New usleep_wrap function registered as usleep intrinsic. * lib.c: Only define setenv and unsetenv if we don't have timegm, because only in that situation they are used. --- eval.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'eval.c') diff --git a/eval.c b/eval.c index c0adfa0c..25a6c0be 100644 --- a/eval.c +++ b/eval.c @@ -33,10 +33,14 @@ #include #include #include +#include #include "config.h" #ifdef HAVE_UNISTD_H #include #endif +#ifdef HAVE_WINDOWS_H +#include +#endif #ifdef HAVE_SYSLOG #include #endif @@ -2110,6 +2114,32 @@ static val exit_wrap(val status) return nil; } +static val usleep_wrap(val usec) +{ + val retval; + cnum u = c_num(usec); + + sig_save_enable; + +#if HAVE_POSIX_NANOSLEEP + struct timespec ts; + ts.tv_sec = u / 1000000; + ts.tv_nsec = (u % 1000000) * 1000; + retval = if3(nanosleep(&ts, 0) == 0, t, nil); +#elif HAVE_POSIX_SLEEP && HAVE_POSIX_USLEEP + retval = if2(sleep(u / 1000000) == 0 && + usleep(u % 1000000) == 0, t); +#elif HAVE_WINDOWS_H + Sleep(u / 1000); + retval = t; +#else +#error port me! +#endif + + sig_restore_enable; + return retval; +} + static void reg_fun(val sym, val fun) { sethash(top_fb, sym, cons(sym, fun)); @@ -2608,6 +2638,7 @@ void eval_init(void) reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0)); reg_fun(intern(lit("exit"), user_package), func_n1(exit_wrap)); + reg_fun(intern(lit("usleep"), user_package), func_n1(usleep_wrap)); #if HAVE_DAEMON reg_fun(intern(lit("daemon"), user_package), func_n2(daemon_wrap)); -- cgit v1.2.3