+(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))
+