summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-10 19:53:11 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-10 19:53:11 -0800
commitf4bd17eab2667962090fc8a918b553badad671bc (patch)
treee1d9568e3ca63300474c7b2789fb0ec4d3089f80
parentaf2af7a4ed4321f955251f9da13a161a1e8940b3 (diff)
downloadtxr-f4bd17eab2667962090fc8a918b553badad671bc.tar.gz
txr-f4bd17eab2667962090fc8a918b553badad671bc.tar.bz2
txr-f4bd17eab2667962090fc8a918b553badad671bc.zip
* 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 <sys/types.h> evidently; <unistd.h> 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 <time.h> and conditionally <windows.h>. (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.
-rwxr-xr-xconfigure69
-rw-r--r--eval.c31
-rw-r--r--lib.c4
3 files changed, 87 insertions, 17 deletions
diff --git a/configure b/configure
index 6a29cab3..337e2427 100755
--- a/configure
+++ b/configure
@@ -82,7 +82,7 @@ yacc='$(cross)$(tool_prefix)$(yaccname)'
yacc_given=
nm='$(cross)$(tool_prefix)nm'
opt_flags=-O2
-lang_flags='-ansi -D_XOPEN_SOURCE=2'
+lang_flags='-ansi -D_BSD_SOURCE -D_POSIX_C_SOURCE=199309L'
diag_flags='-Wall -Wmissing-prototypes -Wstrict-prototypes'
debug_flags=-g
inline=
@@ -656,7 +656,7 @@ printf "okay\n"
printf "Checking whether executables have that idiotic .exe suffix ... "
-if ls conftest.exe > /dev/null ; then
+if ls conftest.exe > /dev/null 2>&1 ; then
echo "yes"
exe=.exe
else
@@ -1253,6 +1253,7 @@ cat > conftest.c <<!
#ifdef HAVE_SYS_WAIT
#include <sys/wait.h>
#endif
+#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv)
@@ -1325,19 +1326,17 @@ int main(void)
}
!
rm -f conftest$exe
-if ! $make EXTRA_FLAGS='-D_SVID_SOURCE' conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+if ! $make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
printf "no\n"
else
printf "yes\n"
printf "#define HAVE_TIMEGM 1\n" >> config.h
have_timegm=y
- need_svid_source=y
fi
-if [ -z "$have_timegm" ] ; then
- printf "Checking for setenv and unsetenv functions ... "
+printf "Checking for setenv and unsetenv functions ... "
- cat > conftest.c <<!
+cat > conftest.c <<!
#include <stdlib.h>
int main(void)
@@ -1347,14 +1346,13 @@ int main(void)
return 0;
}
!
- rm -f conftest$exe
- if ! $make EXTRA_FLAGS='-D_BSD_SOURCE' conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
- printf "no\n"
- else
- printf "yes\n"
- printf "#define HAVE_SETENV 1\n" >> config.h
- need_bsd_source=y
- fi
+rm -f conftest$exe
+if ! $make EXTRA_FLAGS='-D_BSD_SOURCE' conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+ printf "no\n"
+else
+ printf "yes\n"
+ printf "#define HAVE_SETENV 1\n" >> config.h
+ need_bsd_source=y
fi
printf "Checking for tzset function ... "
@@ -1420,6 +1418,47 @@ else
have_unistd=y
fi
+printf "Checking for POSIX usleep function ... "
+
+cat > conftest.c <<!
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+ usleep(42);
+ return 0;
+}
+!
+rm -f conftest$exe
+if ! $make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+ printf "no\n"
+else
+ printf "yes\n"
+ printf "#define HAVE_POSIX_USLEEP 1\n" >> config.h
+ have_unistd=y
+fi
+
+printf "Checking for POSIX nanosleep function ... "
+
+cat > conftest.c <<!
+#include <time.h>
+
+int main(int argc, char **argv)
+{
+ struct timespec ts;
+ nanosleep(&ts, &ts);
+ return 0;
+}
+!
+rm -f conftest$exe
+if ! $make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+ printf "no\n"
+else
+ printf "yes\n"
+ printf "#define HAVE_POSIX_NANOSLEEP 1\n" >> config.h
+ have_unistd=y
+fi
+
printf "Checking for BSD daemon function ... "
cat > conftest.c <<!
diff --git a/eval.c b/eval.c
index c0adfa0c..25a6c0be 100644
--- a/eval.c
+++ b/eval.c
@@ -33,10 +33,14 @@
#include <stdarg.h>
#include <wchar.h>
#include <signal.h>
+#include <time.h>
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_WINDOWS_H
+#include <windows.h>
+#endif
#ifdef HAVE_SYSLOG
#include <syslog.h>
#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));
diff --git a/lib.c b/lib.c
index 194e0c65..9662668b 100644
--- a/lib.c
+++ b/lib.c
@@ -5190,6 +5190,8 @@ val make_time(val year, val month, val day,
return make_time_impl(mktime, year, month, day, hour, minute, second, isdst);
}
+#if !HAVE_TIMEGM
+
#if !HAVE_SETENV
static void
setenv(const char *name, const char *value, int overwrite)
@@ -5206,10 +5208,8 @@ unsetenv(const char *name)
{
setenv(name, "", 1);
}
-
#endif
-#if !HAVE_TIMEGM
static time_t timegm_hack(struct tm *tm)
{
time_t ret;