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 | |
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.
-rw-r--r-- | ChangeLog | 12 | ||||
-rwxr-xr-x | configure | 22 | ||||
-rw-r--r-- | eval.c | 20 | ||||
-rw-r--r-- | txr.1 | 32 |
4 files changed, 86 insertions, 0 deletions
@@ -1,5 +1,17 @@ 2013-11-28 Kaz Kylheku <kaz@kylheku.com> + * 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. + +2013-11-28 Kaz Kylheku <kaz@kylheku.com> + * txr.1: Documented open-tail and make-time. 2013-11-28 Kaz Kylheku <kaz@kylheku.com> @@ -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 <<! @@ -1301,6 +1303,26 @@ else have_unistd=y fi +printf "Checking for BSD daemon function ... " + +cat > conftest.c <<! +#include <unistd.h> + +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 # @@ -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)); @@ -10800,6 +10800,38 @@ If the argument is nil, then the time is assumed not to be in DST. If <dst-advice> 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 [<new-errno>]) + +.TP +Description: + +These functions retrieves the current value of the C library error variable +errno. If the argument <new-errno> 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 <nochdir-p> <noclose-p>) + +.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 |