From 0be7721c52cf2978114de43e391c04437d8d875e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 28 Nov 2013 20:15:08 -0800 Subject: * configure: Detect the daemon function. * eval.c: Include conditionally. (errno_wrap, daemon_wrap): New functions. (eval_init): Registered errno_wrap and daemon_wrap as intrinsics under the names daemon and errno. * txr.1: Documented errno and daemon in new UNIX PROGRAMMING section. --- ChangeLog | 12 ++++++++++++ configure | 22 ++++++++++++++++++++++ eval.c | 20 ++++++++++++++++++++ txr.1 | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+) diff --git a/ChangeLog b/ChangeLog index b4740778..419ff94b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2013-11-28 Kaz Kylheku + + * configure: Detect the daemon function. + + * eval.c: Include conditionally. + (errno_wrap, daemon_wrap): New functions. + (eval_init): Registered errno_wrap and daemon_wrap as intrinsics + under the names daemon and errno. + + * txr.1: Documented errno and daemon in new UNIX PROGRAMMING + section. + 2013-11-28 Kaz Kylheku * txr.1: Documented open-tail and make-time. diff --git a/configure b/configure index fe27ace2..e318ef17 100755 --- a/configure +++ b/configure @@ -1281,6 +1281,8 @@ int x = sizeof ((struct tm *) 0)->$try_field; fi done +printf "done\n" + printf "Checking for POSIX sleep function ... " cat > conftest.c < conftest.c < + +int main(int argc, char **argv) +{ + daemon(0, 0); + return 0; +} +! +rm -f conftest +if ! $make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then + printf "no\n" +else + printf "yes\n" + printf "#define HAVE_DAEMON 1\n" >> config.h + have_unistd=y +fi + # # Dependent variables # diff --git a/eval.c b/eval.c index 395e9abe..4886856c 100644 --- a/eval.c +++ b/eval.c @@ -33,6 +33,9 @@ #include #include #include "config.h" +#ifdef HAVE_UNISTD_H +#include +#endif #include "lib.h" #include "gc.h" #include "unwind.h" @@ -2054,6 +2057,20 @@ static val force(val promise) return rplacd(promise, funcall(cdr(promise))); } +static val errno_wrap(val newval) +{ + val oldval = num(errno); + if (newval) + errno = c_num(newval); + return oldval; +} + +static val daemon_wrap(val nochdir, val noclose) +{ + int result = daemon(nochdir ? 1 : 0, noclose ? 1 : 0); + return result == 0 ? t : nil; +} + static void reg_fun(val sym, val fun) { sethash(top_fb, sym, cons(sym, fun)); @@ -2532,6 +2549,9 @@ void eval_init(void) reg_fun(intern(lit("time-string-utc"), user_package), func_n2(time_string_utc)); reg_fun(intern(lit("make-time"), user_package), func_n7(make_time)); + reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0)); + reg_fun(intern(lit("daemon"), user_package), func_n2(daemon_wrap)); + reg_fun(intern(lit("source-loc"), user_package), func_n1(source_loc)); reg_fun(intern(lit("source-loc-str"), user_package), func_n1(source_loc_str)); diff --git a/txr.1 b/txr.1 index 5df7c02d..a647cf53 100644 --- a/txr.1 +++ b/txr.1 @@ -10800,6 +10800,38 @@ If the argument is nil, then the time is assumed not to be in DST. If is :auto, then the function tries to determine whether DST is in effect in the current time zone for the specified date and time. +.SH UNIX PROGRAMMING + +.SS Functions errno and set-errno + +.TP +Syntax: + + (errno []) + +.TP +Description: + +These functions retrieves the current value of the C library error variable +errno. If the argument is present and is not nil, then it becomes +the new value of errno. The value returned is the prior value. + +.SS Function daemon + +.TP +Syntax: + + (daemon ) + +.TP +Description: + +This is a wrapper for the Unix function daemon of BSD origin. + +It returns t if successful, nil otherwise, and the errno +variable is set in that case. + + .SH WEB PROGRAMMING SUPPORT .SS Functions url-encode and url-decode -- cgit v1.2.3