get_exename() for OpenBSD.
Issue
`get_exename()` gets the pathname of the current process. In
femtolisp, this is used to set the top-level `*install-dir*` which in
turn is used as the location of the system image, `flisp.boot`.
There is only a trivial implementation of `get_exename()` for OpenBSD
that simply returns `NULL`. A minor consequence is that the unit test
will fail for the default build (make) because the system image cannot
be found.
Fix
This commit provides an implementation of `get_exename()` for OpenBSD,
so that the system image can be found.
Unlike, say, Linux or FreeBSD, OpenBSD doesn't have a system call to
get the path of the current (or any, for that matter) process. The
present code contains some logic that was put together to emulate the
behavior of the Linux and FreeBSD variants of `get_exename()` as best
as possible. It works as described by the following.
(1) Call `sysctl(3)` (with `CTL_KERN` -> `KERN_PROC_ARGS` ->
`KERN_PROC_ARGV`) to get the "`argv[0]`" of the current process.
If the program (flisp) was called in "`basename` form" (i.e. as
"flisp"), then go to (2). Otherwise, return the value from
`sysctl(3)` which will be an absolute or relative pathname,
e.g. "/usr/local/bin/flisp" or "../flisp".
The code for (1) was adapted from old OpenBSD-specific `tmux` code
that has since been abandoned by the author only because he deemed
it "too expensive". For that code, see
8c259f562b/tree/osdep-openbsd.c
(2) Since we now only have "flisp", we need to find out where it is
located on the system. We assume that a program like the shell
had to crawl `PATH` to find "flisp"; hence we do the same.
The code for (2) was adapted from the `which` utility in OpenBSD.
See
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/usr.bin/which/which.c?rev=1.20&content-type=text/plain
Finally, any error condition returns `NULL`, which is the same
behavior of the other `get_exename()` variants.
* Resolve relative pathnames to absolute, for OpenBSD get_exename().
It looks like FreeBSD should do what OpenBSD does in femtolisp's code.
The biggest change here (I think) is that of determining the correct
value of CC in the Makefile(s). As of version 10, FreeBSD's base
compiler is clang; so there is now some logic in the Makefile(s) to
determine if the build is occurring on a FreeBSD system >= 10.0. If
so, then the value of CC will be "clang"; otherwise, it will be "gcc",
as before.
fixing open-string-output-port (R6RS)
making io.tostring! more consistent
adding newlines to boot file; wastes space but will allow more
efficient diffing
making io.write output chars as utf8;
suddenly switching to UTF32 was not intuitive
adding stream argument to newline (R6RS)
adding several more scheme compatibility procedures