These interfaces provide access to operating system facilities. They provide a simple wrapping around the underlying C interfaces to make usage from Scheme more convenient. They are also used to implement the Guile port of scsh (see The Scheme shell (scsh)).
Generally there is a single procedure for each corresponding Unix
facility. There are some exceptions, such as procedures implemented for
speed and convenience in Scheme with no primitive Unix equivalent,
The interfaces are intended as far as possible to be portable across different versions of Unix. In some cases procedures which can’t be implemented on particular systems may become no-ops, or perform limited actions. In other cases they may throw errors.
General naming conventions are as follows:
#f) have question marks appended, e.g.,
R_OKare converted to Scheme variables of the same name (underscores are not replaced with hyphens).
Unexpected conditions are generally handled by raising exceptions.
There are a few procedures which return a special value if they don’t
#f if it the requested
string is not found in the environment. These cases are noted in
For ways to deal with exceptions, see Exceptions.
Errors which the C library would report by returning a null pointer or
through some other means are reported by raising a
scm-error (see Error Reporting). The
data parameter is a list containing the Unix
(an integer). For example,
(define (my-handler key func fmt fmtargs data) (display key) (newline) (display func) (newline) (apply format #t fmt fmtargs) (newline) (display data) (newline)) (catch 'system-error (lambda () (dup2 -123 -456)) my-handler) -| system-error dup2 Bad file descriptor (9)
errno value from a list which is the arguments to an
exception handler. If the exception is not a
then the return is
#f. For example,
(catch 'system-error (lambda () (mkdir "/this-ought-to-fail-if-I'm-not-root")) (lambda stuff (let ((errno (system-error-errno stuff))) (cond ((= errno EACCES) (display "You're not allowed to do that.")) ((= errno EEXIST) (display "Already exists.")) (#t (display (strerror errno)))) (newline))))