+\f
+;;; stat-mode tests
+(defmacro with-stat-mode ((mode pathname) &body body)
+ (let ((stat (gensym)))
+ `(let* ((,stat (sb-posix:stat ,pathname))
+ (,mode (sb-posix::stat-mode ,stat)))
+ ,@body)))
+
+(defmacro with-lstat-mode ((mode pathname) &body body)
+ (let ((stat (gensym)))
+ `(let* ((,stat (sb-posix:lstat ,pathname))
+ (,mode (sb-posix::stat-mode ,stat)))
+ ,@body)))
+
+(deftest stat-mode.1
+ (with-stat-mode (mode *test-directory*)
+ (sb-posix:s-isreg mode))
+ nil)
+
+(deftest stat-mode.2
+ (with-stat-mode (mode *test-directory*)
+ (sb-posix:s-isdir mode))
+ t)
+
+(deftest stat-mode.3
+ (with-stat-mode (mode *test-directory*)
+ (sb-posix:s-ischr mode))
+ nil)
+
+(deftest stat-mode.4
+ (with-stat-mode (mode *test-directory*)
+ (sb-posix:s-isblk mode))
+ nil)
+
+(deftest stat-mode.5
+ (with-stat-mode (mode *test-directory*)
+ (sb-posix:s-isfifo mode))
+ nil)
+
+(deftest stat-mode.6
+ (with-stat-mode (mode *test-directory*)
+ (sb-posix:s-issock mode))
+ nil)
+
+(deftest stat-mode.7
+ (let ((link-pathname (make-pathname :name "stat-mode.7"
+ :defaults *test-directory*)))
+ (unwind-protect
+ (progn
+ (sb-posix:symlink *test-directory* link-pathname)
+ (with-lstat-mode (mode link-pathname)
+ (sb-posix:s-islnk mode)))
+ (ignore-errors (sb-posix:unlink link-pathname))))
+ t)
+
+(deftest stat-mode.8
+ (let ((pathname (make-pathname :name "stat-mode.8"
+ :defaults *test-directory*)))
+ (unwind-protect
+ (progn
+ (with-open-file (out pathname :direction :output)
+ (write-line "test" out))
+ (with-stat-mode (mode pathname)
+ (sb-posix:s-isreg mode)))
+ (ignore-errors (delete-file pathname))))
+ t)
+\f
+;;; see comment in filename's designator definition, in macros.lisp
+(deftest filename-designator.1
+ (let ((file (format nil "~A/[foo].txt" (namestring *test-directory*))))
+ ;; creat() with a string as argument
+ (sb-posix:creat file 0)
+ ;; if this test fails, it will probably be with
+ ;; "System call error 2 (No such file or directory)"
+ (let ((*default-pathname-defaults* *test-directory*))
+ (sb-posix:unlink (car (directory "*.txt")))))
+ 0)
+\f
+(deftest open.1
+ (let ((fd (sb-posix:open *test-directory* sb-posix::o-rdonly)))
+ (ignore-errors (sb-posix:close fd))
+ (< fd 0))
+ nil)
+
+(deftest open.error.1
+ (handler-case (sb-posix:open *test-directory* sb-posix::o-wronly)
+ (sb-posix:syscall-error (c)
+ (sb-posix:syscall-errno c)))
+ #.sb-posix::eisdir)
+
+(deftest fcntl.1
+ (let ((fd (sb-posix:open "/dev/null" sb-posix::o-nonblock)))
+ (= (sb-posix:fcntl fd sb-posix::f-getfl) sb-posix::o-nonblock))
+ t)
+
+
+(deftest opendir.1
+ (let ((dir (sb-posix:opendir "/")))
+ (unwind-protect (sb-alien:null-alien dir)
+ (unless (sb-alien:null-alien dir)
+ (sb-posix:closedir dir))))
+ nil)
+
+(deftest readdir.1
+ (let ((dir (sb-posix:opendir "/")))
+ (unwind-protect
+ (block dir-loop
+ (loop for dirent = (sb-posix:readdir dir)
+ until (sb-alien:null-alien dirent)
+ when (not (stringp (sb-posix:dirent-name dirent)))
+ do (return-from dir-loop nil)
+ finally (return t)))
+ (sb-posix:closedir dir)))
+ t)