diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-11-28 20:15:08 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-11-28 20:15:08 -0800 |
commit | 0be7721c52cf2978114de43e391c04437d8d875e (patch) | |
tree | 89167b68f4c7fe05882b17cfe8b538c8608f51f3 /eval.c | |
parent | 18832d8a641ff25fefccddd34c0325bc8089a69c (diff) | |
download | txr-0be7721c52cf2978114de43e391c04437d8d875e.tar.gz txr-0be7721c52cf2978114de43e391c04437d8d875e.tar.bz2 txr-0be7721c52cf2978114de43e391c04437d8d875e.zip |
* configure: Detect the daemon function.
* eval.c: Include <unistd.h> 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.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -33,6 +33,9 @@ #include <stdarg.h> #include <wchar.h> #include "config.h" +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#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)); |