+#-(or hpux win32) ; fix: cant handle c-vargs
+(deftest fcntl.flock.1
+ (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
+ (let ((flock (make-instance 'sb-posix:flock
+ :type sb-posix:f-wrlck
+ :whence sb-posix:seek-set
+ :start 0 :len 10))
+ (pathname "fcntl.flock.1")
+ kid-status)
+ (catch 'test
+ (with-open-file (f pathname :direction :output)
+ (write-line "1234567890" f)
+ (assert (zerop (sb-posix:fcntl f sb-posix:f-setlk flock)))
+ (let ((pid (sb-posix:fork)))
+ (if (zerop pid)
+ (progn
+ (multiple-value-bind (nope error)
+ (ignore-errors (sb-posix:fcntl f sb-posix:f-setlk flock))
+ (sb-ext:exit
+ :code
+ (cond ((not (null nope)) 1)
+ ((= (sb-posix:syscall-errno error) sb-posix:eagain)
+ 42)
+ (t 86))
+ :abort t #| don't delete the file |#)))
+ (progn
+ (setf kid-status
+ (sb-posix:wexitstatus
+ (nth-value
+ 1 (sb-posix:waitpid pid 0))))
+ (throw 'test nil))))))
+ kid-status))
+ 42)
+
+
+#-(or win32 netbsd)
+(deftest fcntl.flock.2
+ (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
+ (let ((flock (make-instance 'sb-posix:flock
+ :type sb-posix:f-wrlck
+ :whence sb-posix:seek-set
+ :start 0 :len 10))
+ (pathname "fcntl.flock.2")
+ kid-status)
+ (catch 'test
+ (with-open-file (f pathname :direction :output)
+ (write-line "1234567890" f)
+ (assert (zerop (sb-posix:fcntl f sb-posix:f-setlk flock)))
+ (let ((ppid (sb-posix:getpid))
+ (pid (sb-posix:fork)))
+ (if (zerop pid)
+ (let ((r (sb-posix:fcntl f sb-posix:f-getlk flock)))
+ (sb-ext:exit
+ :code
+ (cond ((not (zerop r)) 1)
+ ((= (sb-posix:flock-pid flock) ppid) 42)
+ (t 86))
+ :abort t #| don't delete the file |#))
+ (progn
+ (setf kid-status
+ (sb-posix:wexitstatus
+ (nth-value
+ 1 (sb-posix:waitpid pid 0))))
+ (throw 'test nil))))))
+ kid-status))
+ 42)
+
+(deftest read.1
+ (progn
+ (with-open-file (ouf (merge-pathnames "read-test.txt" *test-directory*)
+ :direction :output
+ :if-exists :supersede
+ :if-does-not-exist :create)
+ (write-string "foo" ouf))
+ (let ((fd (sb-posix:open (merge-pathnames "read-test.txt" *test-directory*) sb-posix:o-rdonly)))
+ (unwind-protect
+ (let ((buf (make-array 10 :element-type '(unsigned-byte 8))))
+ (values
+ (sb-posix:read fd (sb-sys:vector-sap buf) 10)
+ (code-char (aref buf 0))
+ (code-char (aref buf 1))
+ (code-char (aref buf 2))))
+ (sb-posix:close fd))))
+ 3 #\f #\o #\o)
+