X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-posix%2Finterface.lisp;h=0bd5675c1bbac47d2048d97840a1a17b3869c10b;hb=eaa8a506790bb6ed627da617247bfd13802eb365;hp=1e78322c750302f3723728b7968438d132a89eea;hpb=74fab9d286412e5f4bedcc0832101a0cd95857c8;p=sbcl.git diff --git a/contrib/sb-posix/interface.lisp b/contrib/sb-posix/interface.lisp index 1e78322..0bd5675 100644 --- a/contrib/sb-posix/interface.lisp +++ b/contrib/sb-posix/interface.lisp @@ -76,6 +76,7 @@ (define-call "chmod" int minusp (pathname filename) (mode sb-posix::mode-t)) (define-call "chown" int minusp (pathname filename) (owner sb-posix::uid-t) (group sb-posix::gid-t)) +(define-call "chroot" int minusp (pathname filename)) (define-call "close" int minusp (fd file-descriptor)) (define-call "creat" int minusp (pathname filename) (mode sb-posix::mode-t)) (define-call "dup" int minusp (oldfd file-descriptor)) @@ -106,6 +107,7 @@ (define-call "sync" void never-fails) (define-call "truncate" int minusp (pathname filename) (length sb-posix::off-t)) (define-call "unlink" int minusp (pathname filename)) +(define-call "mkstemp" int minusp (template c-string)) (define-call-internally ioctl-without-arg "ioctl" int minusp (fd file-descriptor) (cmd int)) (define-call-internally ioctl-with-int-arg "ioctl" int minusp (fd file-descriptor) (cmd int) (arg int)) @@ -128,7 +130,7 @@ (fcntl-without-arg fd cmd))) (define-call "opendir" (* t) null-alien (pathname filename)) -(define-call "readdir" sb-posix::dirent +(define-call "readdir" (* sb-posix::dirent) ;; readdir() has the worst error convention in the world. It's just ;; too painful to support. (return is NULL _and_ errno "unchanged" ;; is not an error, it's EOF). @@ -166,6 +168,7 @@ ;;; processes, signals (define-call "alarm" int never-fails (seconds unsigned)) +(define-call "fork" sb-posix::pid-t minusp) (define-call "getpgid" sb-posix::pid-t minusp (pid sb-posix::pid-t)) (define-call "getpid" sb-posix::pid-t never-fails) (define-call "getppid" sb-posix::pid-t never-fails) @@ -178,12 +181,47 @@ (pid sb-posix::pid-t) (pgid sb-posix::pid-t)) (define-call "setpgrp" int minusp) +(export 'sb-posix::wait :sb-posix) +(declaim (inline sb-posix::wait)) +(defun sb-posix::wait (&optional statusptr) + (declare (type (or null (simple-array (signed-byte 32) (1))) statusptr)) + (let* ((ptr (or statusptr (make-array 1 :element-type '(signed-byte 32)))) + (pid (alien-funcall + (extern-alien "wait" (function sb-posix::pid-t (* int))) + (sb-sys:vector-sap ptr)))) + (if (minusp pid) + (syscall-error) + (values pid (aref ptr 0))))) + +(export 'sb-posix::waitpid :sb-posix) +(declaim (inline sb-posix::waitpid)) +(defun sb-posix::waitpid (pid options &optional statusptr) + (declare (type (sb-alien:alien sb-posix::pid-t) pid) + (type (sb-alien:alien int) options) + (type (or null (simple-array (signed-byte 32) (1))) statusptr)) + (let* ((ptr (or statusptr (make-array 1 :element-type '(signed-byte 32)))) + (pid (alien-funcall + (extern-alien "waitpid" (function sb-posix::pid-t + sb-posix::pid-t (* int) int)) + pid (sb-sys:vector-sap ptr) options))) + (if (minusp pid) + (syscall-error) + (values pid (aref ptr 0))))) + +;; waitpid macros +(define-call "wifexited" boolean never-fails (status int)) +(define-call "wexitstatus" int never-fails (status int)) +(define-call "wifsignaled" boolean never-fails (status int)) +(define-call "wtermsig" int never-fails (status int)) +(define-call "wifstopped" boolean never-fails (status int)) +(define-call "wstopsig" int never-fails (status int)) +#+nil ; see alien/waitpid-macros.c +(define-call "wifcontinued" boolean never-fails (status int)) + ;;; mmap, msync (define-call "mmap" sb-sys:system-area-pointer - ;; KLUDGE: #XFFFFFFFF is (void *)-1, which is the charming return - ;; value of mmap on failure. Except on 64 bit systems ... (lambda (res) - (= (sb-sys:sap-int res) #-alpha #XFFFFFFFF #+alpha #xffffffffffffffff)) + (= (sb-sys:sap-int res) #.(1- (expt 2 sb-vm::n-machine-word-bits)))) (addr sap-or-nil) (length unsigned) (prot unsigned) (flags unsigned) (fd file-descriptor) (offset sb-posix::off-t)) @@ -289,3 +327,15 @@ (syscall-error)) (setf termios (alien-to-termios a-termios termios)))) termios) + +;;; environment + +(export 'sb-posix::getenv :sb-posix) +(defun sb-posix::getenv (name) + (let ((r (alien-funcall + (extern-alien "getenv" (function (* char) c-string)) + name))) + (declare (type (alien (* char)) r)) + (unless (null-alien r) + (cast r c-string)))) +(define-call "putenv" int minusp (string c-string))