1 (defpackage "SB-POSIX-TESTS"
2 (:use
"COMMON-LISP" "SB-RT"))
4 (in-package "SB-POSIX-TESTS")
6 (defvar *test-directory
*
7 (ensure-directories-exist
8 (merge-pathnames (make-pathname :directory
'(:relative
"test-output"))
9 (make-pathname :directory
10 (pathname-directory *load-truename
*)))))
12 (defvar *current-directory
* *default-pathname-defaults
*)
14 (defvar *this-file
* *load-truename
*)
16 (eval-when (:compile-toplevel
:load-toplevel
)
17 (defconstant +mode-rwx-all
+
18 (logior sb-posix
::s-irusr sb-posix
::s-iwusr sb-posix
::s-ixusr
21 sb-posix
::s-irgrp sb-posix
::s-iwgrp sb-posix
::s-ixgrp
22 sb-posix
::s-iroth sb-posix
::s-iwoth sb-posix
::s-ixoth
))))
24 (defmacro define-eacces-test
(name form
&rest values
)
28 (when (= (sb-posix:geteuid
) 0)
29 (return-from ,name
(values ,@values
)))
34 (sb-posix:chdir
*test-directory
*)
38 (sb-posix:chdir
(namestring *test-directory
*))
46 (sb-posix:chdir
#p
"/")
50 (sb-posix:chdir
*current-directory
*)
54 (sb-posix:chdir
"/../")
58 (sb-posix:chdir
#p
"/../")
62 (sb-posix:chdir
(make-pathname :directory
'(:absolute
:up
)))
65 (deftest chdir.error
.1
66 (let ((dne (make-pathname :directory
'(:relative
"chdir.does-not-exist"))))
68 (sb-posix:chdir
(merge-pathnames dne
*test-directory
*))
69 (sb-posix:syscall-error
(c)
70 (sb-posix:syscall-errno c
))))
73 (deftest chdir.error
.2
75 (sb-posix:chdir
*this-file
*)
76 (sb-posix:syscall-error
(c)
77 (sb-posix:syscall-errno c
)))
84 (let ((dne (make-pathname :directory
'(:relative
"mkdir.does-not-exist.1"))))
86 (sb-posix:mkdir
(merge-pathnames dne
*test-directory
*) 0)
87 ;; FIXME: no delete-directory in CL, but using our own operators
88 ;; is probably not ideal
89 (ignore-errors (sb-posix:rmdir
(merge-pathnames dne
*test-directory
*)))))
93 (let ((dne (make-pathname :directory
'(:relative
"mkdir.does-not-exist.2"))))
95 (sb-posix:mkdir
(namestring (merge-pathnames dne
*test-directory
*)) 0)
96 (ignore-errors (sb-posix:rmdir
(merge-pathnames dne
*test-directory
*)))))
99 (deftest mkdir.error
.1
101 (sb-posix:mkdir
*test-directory
* 0)
102 (sb-posix:syscall-error
(c)
103 (sb-posix:syscall-errno c
)))
106 (deftest mkdir.error
.2
108 (sb-posix:mkdir
#-win32
"/" #+win32
"C:/" 0)
109 (sb-posix:syscall-error
(c)
110 ;; The results aren't the most consistent ones across platforms. Darwin
111 ;; likes EISDIR, Windows either EACCESS or EEXIST, others EEXIST.
112 ;; ...let's just accept them all.
113 (when (member (sb-posix:syscall-errno c
)
114 (list #.sb-posix
:eisdir
121 (define-eacces-test mkdir.error
.3
122 (let* ((dir (merge-pathnames
123 (make-pathname :directory
'(:relative
"mkdir.error.3"))
125 (dir2 (merge-pathnames
126 (make-pathname :directory
'(:relative
"does-not-exist"))
128 (sb-posix:mkdir dir
0)
130 (sb-posix:mkdir dir2
0)
131 (sb-posix:syscall-error
(c)
133 (sb-posix:syscall-errno c
))
135 (sb-posix:rmdir dir2
)
141 (let ((dne (make-pathname :directory
'(:relative
"rmdir.does-not-exist.1"))))
142 (ensure-directories-exist (merge-pathnames dne
*test-directory
*))
143 (sb-posix:rmdir
(merge-pathnames dne
*test-directory
*)))
147 (let ((dne (make-pathname :directory
'(:relative
"rmdir.does-not-exist.2"))))
148 (ensure-directories-exist (merge-pathnames dne
*test-directory
*))
149 (sb-posix:rmdir
(namestring (merge-pathnames dne
*test-directory
*))))
152 (deftest rmdir.error
.1
153 (let ((dne (make-pathname :directory
'(:relative
"rmdir.dne.error.1"))))
155 (sb-posix:rmdir
(merge-pathnames dne
*test-directory
*))
156 (sb-posix:syscall-error
(c)
157 (sb-posix:syscall-errno c
))))
160 (deftest rmdir.error
.2
162 (sb-posix:rmdir
*this-file
*)
163 (sb-posix:syscall-error
(c)
164 (sb-posix:syscall-errno c
)))
170 (deftest rmdir.error
.3
172 (sb-posix:rmdir
#-win32
"/" #+win32
(sb-ext:posix-getenv
"windir"))
173 (sb-posix:syscall-error
(c)
175 (sb-posix:syscall-errno c
)
177 #+(or darwin openbsd
)
182 #.sb-posix
::enotempty
185 #-
(or darwin openbsd win32 sunos
)
186 #.sb-posix
::ebusy
)))) t
)
188 (deftest rmdir.error
.4
189 (let* ((dir (ensure-directories-exist
191 (make-pathname :directory
'(:relative
"rmdir.error.4"))
193 (file (make-pathname :name
"foo" :defaults dir
)))
194 (with-open-file (s file
:direction
:output
:if-exists nil
)
195 (write "" :stream s
))
198 (sb-posix:syscall-error
(c)
201 (let ((errno (sb-posix:syscall-errno c
)))
202 ;; documented by POSIX
203 (or (= errno sb-posix
::eexist
) (= errno sb-posix
::enotempty
))))))
206 (define-eacces-test rmdir.error
.5
207 (let* ((dir (merge-pathnames
208 (make-pathname :directory
'(:relative
"rmdir.error.5"))
210 (dir2 (merge-pathnames
211 (make-pathname :directory
'(:relative
"unremovable"))
213 (sb-posix:mkdir dir
+mode-rwx-all
+)
214 (sb-posix:mkdir dir2
+mode-rwx-all
+)
215 (sb-posix:chmod dir
0)
217 (sb-posix:rmdir dir2
)
218 (sb-posix:syscall-error
(c)
219 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
220 (sb-posix:rmdir dir2
)
222 (sb-posix:syscall-errno c
))
224 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
229 #-
(or (and darwin x86
) win32
)
231 (let* ((stat (sb-posix:stat
*test-directory
*))
232 (mode (sb-posix::stat-mode stat
)))
233 ;; FIXME: Ugly ::s everywhere
234 (logand mode
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
)))
235 #.
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
237 #-
(or (and darwin x86
) win32
)
239 (let* ((stat (sb-posix:stat
"/"))
240 (mode (sb-posix::stat-mode stat
)))
241 ;; it's logically possible for / to be writeable by others... but
242 ;; if it is, either someone is playing with strange security
243 ;; modules or they want to know about it anyway.
244 (logand mode sb-posix
::s-iwoth
))
248 (let* ((now (get-universal-time))
249 ;; FIXME: (encode-universal-time 00 00 00 01 01 1970)
250 (unix-now (- now
2208988800))
251 (stat (sb-posix:stat
*test-directory
*))
252 (atime (sb-posix::stat-atime stat
)))
253 ;; FIXME: breaks if mounted noatime :-(
254 #+nil
(< (- atime unix-now
) 10)
255 (< (- atime unix-now
) 10))
258 #-
(or (and darwin x86
) win32
)
260 (let* ((stat (sb-posix:stat
(make-pathname :directory
'(:absolute
:up
))))
261 (mode (sb-posix::stat-mode stat
)))
262 ;; it's logically possible for / to be writeable by others... but
263 ;; if it is, either someone is playing with strange security
264 ;; modules or they want to know about it anyway.
265 (logand mode sb-posix
::s-iwoth
))
268 ;; Test that stat can take a second argument.
271 (let* ((stat-1 (sb-posix:stat
"/"))
272 (inode-1 (sb-posix:stat-ino stat-1
))
273 (stat-2 (sb-posix:stat
"/bin/sh"
275 (inode-2 (sb-posix:stat-ino stat-2
)))
278 (/= inode-1 inode-2
)))
284 (let ((f (namestring (merge-pathnames "some.file" *test-directory
*))))
285 (close (open f
:if-exists
:append
:if-does-not-exist
:create
))
286 (let* ((stat-1 (sb-posix:stat
"/"))
287 (mode-1 (sb-posix:stat-mode stat-1
))
288 (stat-2 (sb-posix:stat f stat-1
))
289 (mode-2 (sb-posix:stat-mode stat-2
)))
292 (/= mode-1 mode-2
))))
296 ;;; FIXME: add tests for carrying a stat structure around in the
297 ;;; optional argument to SB-POSIX:STAT
299 (deftest stat.error
.1
300 (handler-case (sb-posix:stat
"")
301 (sb-posix:syscall-error
(c)
302 (sb-posix:syscall-errno c
)))
305 (define-eacces-test stat.error
.2
306 (let* ((dir (merge-pathnames
307 (make-pathname :directory
'(:relative
"stat.error.2"))
309 (file (merge-pathnames
310 (make-pathname :name
"unstatable")
312 (sb-posix:mkdir dir
+mode-rwx-all
+)
313 (with-open-file (s file
:direction
:output
)
314 (write "" :stream s
))
315 (sb-posix:chmod dir
0)
318 (sb-posix:syscall-error
(c)
319 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
320 (sb-posix:unlink file
)
322 (sb-posix:syscall-errno c
))
324 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
325 (sb-posix:unlink file
)
331 (defmacro with-stat-mode
((mode pathname
) &body body
)
332 (let ((stat (gensym)))
333 `(let* ((,stat
(sb-posix:stat
,pathname
))
334 (,mode
(sb-posix::stat-mode
,stat
)))
337 (defmacro with-lstat-mode
((mode pathname
) &body body
)
338 (let ((stat (gensym)))
339 `(let* ((,stat
(sb-posix:lstat
,pathname
))
340 (,mode
(sb-posix::stat-mode
,stat
)))
344 (with-stat-mode (mode *test-directory
*)
345 (sb-posix:s-isreg mode
))
350 (with-stat-mode (mode *test-directory
*)
351 (sb-posix:s-isdir mode
))
355 (with-stat-mode (mode *test-directory
*)
356 (sb-posix:s-ischr mode
))
360 (with-stat-mode (mode *test-directory
*)
361 (sb-posix:s-isblk mode
))
365 (with-stat-mode (mode *test-directory
*)
366 (sb-posix:s-isfifo mode
))
369 #-
(or (and darwin x86
) win32
)
371 (with-stat-mode (mode *test-directory
*)
372 (sb-posix:s-issock mode
))
375 #-
(or (and darwin x86
) win32
)
377 (let ((link-pathname (make-pathname :name
"stat-mode.7"
378 :defaults
*test-directory
*)))
381 (sb-posix:symlink
*test-directory
* link-pathname
)
382 (with-lstat-mode (mode link-pathname
)
383 (sb-posix:s-islnk mode
)))
384 (ignore-errors (sb-posix:unlink link-pathname
))))
389 (let ((pathname (make-pathname :name
"stat-mode.8"
390 :defaults
*test-directory
*)))
393 (with-open-file (out pathname
:direction
:output
)
394 (write-line "test" out
))
395 (with-stat-mode (mode pathname
)
396 (sb-posix:s-isreg mode
)))
397 (ignore-errors (delete-file pathname
))))
400 ;;; see comment in filename's designator definition, in macros.lisp
401 (deftest filename-designator
.1
402 (let ((file (format nil
"~A/[foo].txt" (namestring *test-directory
*))))
403 ;; creat() with a string as argument
404 (let ((fd (sb-posix:creat file sb-posix
:s-iwrite
)))
407 ;; if this test fails, it will probably be with
408 ;; "System call error 2 (No such file or directory)"
409 (let ((*default-pathname-defaults
* *test-directory
*))
410 (sb-posix:unlink
(car (directory "*.txt")))))
414 (let ((name (merge-pathnames "open-test.txt" *test-directory
*)))
418 (sb-posix:creat name
(logior sb-posix
:s-iwrite sb-posix
:s-iread
)))
419 (let ((fd (sb-posix:open name sb-posix
::o-rdonly
)))
420 (ignore-errors (sb-posix:close fd
))
422 (ignore-errors (sb-posix:unlink name
))))
425 #-hpux
; fix: cant handle c-vargs
426 (deftest open.error
.1
427 (handler-case (sb-posix:open
*test-directory
* sb-posix
::o-wronly
)
428 (sb-posix:syscall-error
(c)
429 (sb-posix:syscall-errno c
)))
435 #-
(or (and (or x86-64 arm64 alpha
) (or linux sunos
)) win32
)
437 (let ((fd (sb-posix:open
"/dev/null" sb-posix
::o-nonblock
)))
438 (= (sb-posix:fcntl fd sb-posix
::f-getfl
) sb-posix
::o-nonblock
))
440 ;; On AMD64/Linux O_LARGEFILE is always set, even though the whole
441 ;; flag makes no sense.
442 #+(and (or x86-64 arm64 alpha
) (or linux sunos
))
444 (let ((fd (sb-posix:open
"/dev/null" sb-posix
::o-nonblock
)))
445 (/= 0 (logand (sb-posix:fcntl fd sb-posix
::f-getfl
)
446 sb-posix
::o-nonblock
)))
449 #-
(or hpux win32 netbsd
) ; fix: cant handle c-vargs
450 (deftest fcntl.flock
.1
451 (locally (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
452 (let ((flock (make-instance 'sb-posix
:flock
453 :type sb-posix
:f-wrlck
454 :whence sb-posix
:seek-set
456 (pathname "fcntl.flock.1")
459 (with-open-file (f pathname
:direction
:output
)
460 (write-line "1234567890" f
)
461 (assert (zerop (sb-posix:fcntl f sb-posix
:f-setlk flock
)))
462 (let ((pid (sb-posix:fork
)))
465 (multiple-value-bind (nope error
)
466 (ignore-errors (sb-posix:fcntl f sb-posix
:f-setlk flock
))
469 (cond ((not (null nope
)) 1)
470 ((= (sb-posix:syscall-errno error
) sb-posix
:eagain
)
473 :abort t
#| don
't delete the file |
#)))
476 (sb-posix:wexitstatus
478 1 (sb-posix:waitpid pid
0))))
479 (throw 'test nil
))))))
485 (deftest fcntl.flock
.2
486 (locally (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
487 (let ((flock (make-instance 'sb-posix
:flock
488 :type sb-posix
:f-wrlck
489 :whence sb-posix
:seek-set
491 (pathname "fcntl.flock.2")
494 (with-open-file (f pathname
:direction
:output
)
495 (write-line "1234567890" f
)
496 (assert (zerop (sb-posix:fcntl f sb-posix
:f-setlk flock
)))
497 (let ((ppid (sb-posix:getpid
))
498 (pid (sb-posix:fork
)))
500 (let ((r (sb-posix:fcntl f sb-posix
:f-getlk flock
)))
503 (cond ((not (zerop r
)) 1)
504 ((= (sb-posix:flock-pid flock
) ppid
) 42)
506 :abort t
#| don
't delete the file |
#))
509 (sb-posix:wexitstatus
511 1 (sb-posix:waitpid pid
0))))
512 (throw 'test nil
))))))
518 (with-open-file (ouf (merge-pathnames "read-test.txt" *test-directory
*)
520 :if-exists
:supersede
521 :if-does-not-exist
:create
)
522 (write-string "foo" ouf
))
523 (let ((fd (sb-posix:open
(merge-pathnames "read-test.txt" *test-directory
*) sb-posix
:o-rdonly
)))
525 (let ((buf (make-array 10 :element-type
'(unsigned-byte 8))))
527 (sb-posix:read fd
(sb-sys:vector-sap buf
) 10)
528 (code-char (aref buf
0))
529 (code-char (aref buf
1))
530 (code-char (aref buf
2))))
531 (sb-posix:close fd
))))
535 (let ((dir (sb-posix:opendir
"/")))
536 (unwind-protect (sb-alien:null-alien dir
)
537 (unless (sb-alien:null-alien dir
)
538 (sb-posix:closedir dir
))))
543 (let ((dir (sb-posix:opendir
"/")))
546 (loop for dirent
= (sb-posix:readdir dir
)
547 until
(sb-alien:null-alien dirent
)
548 when
(not (stringp (sb-posix:dirent-name dirent
)))
549 do
(return-from dir-loop nil
)
551 (sb-posix:closedir dir
)))
555 (deftest readdir
/dirent-name
556 (let ((dir (sb-posix:opendir
*current-directory
*)))
558 (equal (sort (loop for entry
= (sb-posix:readdir dir
)
559 until
(sb-alien:null-alien entry
)
560 collect
(sb-posix:dirent-name entry
))
562 (sort (append '("." "..")
564 (let ((string (enough-namestring p
*current-directory
*)))
565 (if (pathname-name p
)
567 (subseq string
0 (1- (length string
))))))
568 (directory (make-pathname
571 :defaults
*current-directory
*))))
573 (sb-posix:closedir dir
)))
579 (let ((fd (sb-posix:open
(merge-pathnames "write-test.txt" *test-directory
*)
580 (logior sb-posix
:o-creat sb-posix
:o-wronly
)
581 (logior sb-posix
:s-irusr sb-posix
:s-iwusr
)))
584 (let ((buf (coerce "foo" 'simple-base-string
)))
585 (setf retval
(sb-posix:write fd
(sb-sys:vector-sap buf
) 3)))
588 (with-open-file (inf (merge-pathnames "write-test.txt" *test-directory
*)
590 (values retval
(read-line inf
)))))
595 ;; make sure that we found something
596 (not (sb-posix:getpwuid
0))
601 ;; make sure that we found something
602 (not (sb-posix:getpwnam
"root"))
606 (deftest pwent.non-existing
607 ;; make sure that we get something sensible, not an error
608 (handler-case (progn (sb-posix:getpwnam
"almost-certainly-does-not-exist")
615 ;; make sure that we found something
616 (not (sb-posix:getgrgid
0))
621 ;; make sure that we found something
622 (not (sb-posix:getgrnam
"sys"))
626 (deftest grent.non-existing
627 ;; make sure that we get something sensible, not an error
628 (handler-case (progn (sb-posix:getgrnam
"almost-certainly-does-not-exist")
634 ;; Requires root or special group + plus a sensible thing on the port
635 (deftest cfget
/setispeed
.1
636 (with-open-file (s "/dev/ttyS0")
637 (let* ((termios (sb-posix:tcgetattr s
))
638 (old (sb-posix:cfgetispeed termios
))
639 (new (if (= old sb-posix
:b2400
)
642 (sb-posix:cfsetispeed new termios
)
643 (sb-posix:tcsetattr
0 sb-posix
:tcsadrain termios
)
644 (setf termios
(sb-posix:tcgetattr s
))
645 (= new
(sb-posix:cfgetispeed termios
))))
649 ;; Requires root or special group + a sensible thing on the port
650 (deftest cfget
/setospeed
.1
651 (with-open-file (s "/dev/ttyS0" :direction
:output
:if-exists
:append
)
652 (let* ((termios (sb-posix:tcgetattr s
))
653 (old (sb-posix:cfgetospeed termios
))
654 (new (if (= old sb-posix
:b2400
)
657 (sb-posix:cfsetospeed new termios
)
658 (sb-posix:tcsetattr
0 sb-posix
:tcsadrain termios
)
659 (setf termios
(sb-posix:tcgetattr
0))
660 (= new
(sb-posix:cfgetospeed termios
))))
666 (plusp (sb-posix:time
))
669 #-
(or (and darwin x86
) win32
)
671 (let ((file (merge-pathnames #p
"utimes.1" *test-directory
*))
672 (atime (random (1- (expt 2 31))))
673 (mtime (random (1- (expt 2 31)))))
674 (with-open-file (stream file
676 :if-exists
:supersede
677 :if-does-not-exist
:create
)
678 (princ "Hello, utimes" stream
))
679 (sb-posix:utime file atime mtime
)
680 (let* ((stat (sb-posix:stat file
)))
682 (list (= (sb-posix:stat-atime stat
) atime
)
683 (= (sb-posix:stat-mtime stat
) mtime
))))
690 (let ((link-pathname (make-pathname :name
"readlink.1"
691 :defaults
*test-directory
*)))
692 (sb-posix:symlink
"/" link-pathname
)
694 (sb-posix:readlink link-pathname
)
695 (ignore-errors (sb-posix:unlink link-pathname
))))
698 ;; Same thing, but with a very long link target (which doesn't have
699 ;; to exist). This tests the array adjustment in the wrapper,
700 ;; provided that the target's length is long enough.
701 #-hpux
; arg2 to readlink is 80, and arg0 is larger than that
703 (let ((target-pathname (make-pathname
704 :name
(make-string 255 :initial-element
#\a)
705 :directory
'(:absolute
)))
706 (link-pathname (make-pathname :name
"readlink.2"
707 :defaults
*test-directory
*)))
708 (sb-posix:symlink target-pathname link-pathname
)
710 (sb-posix:readlink link-pathname
)
711 (ignore-errors (sb-posix:unlink link-pathname
))))
712 #.
(concatenate 'string
"/" (make-string 255 :initial-element
#\a)))
714 ;; The error tests are in the order of exposition from SUSv3.
715 (deftest readlink.error
.1
716 (let* ((subdir-pathname (merge-pathnames
718 :directory
'(:relative
"readlink.error.1"))
720 (link-pathname (make-pathname :name
"readlink.error.1"
721 :defaults subdir-pathname
)))
722 (sb-posix:mkdir subdir-pathname
#o777
)
723 (sb-posix:symlink
"/" link-pathname
)
724 (sb-posix:chmod subdir-pathname
0)
726 (handler-case (sb-posix:readlink link-pathname
)
727 (sb-posix:syscall-error
(c)
728 (sb-posix:syscall-errno c
)))
730 (sb-posix:chmod subdir-pathname
#o777
)
731 (sb-posix:unlink link-pathname
)
732 (sb-posix:rmdir subdir-pathname
))))
734 (deftest readlink.error
.2
735 (let* ((non-link-pathname (make-pathname :name
"readlink.error.2"
736 :defaults
*test-directory
*))
737 (fd (sb-posix:open non-link-pathname sb-posix
::o-creat
)))
739 (handler-case (sb-posix:readlink non-link-pathname
)
740 (sb-posix:syscall-error
(c)
741 (sb-posix:syscall-errno c
)))
744 (sb-posix:unlink non-link-pathname
))))
746 ;; Skipping EIO, ELOOP
747 (deftest readlink.error
.3
748 (let* ((link-pathname (make-pathname :name
"readlink.error.3"
749 :defaults
*test-directory
*))
750 (bogus-pathname (merge-pathnames
753 :directory
'(:relative
"readlink.error.3"))
755 (sb-posix:symlink link-pathname link-pathname
)
757 (handler-case (sb-posix:readlink bogus-pathname
)
758 (sb-posix:syscall-error
(c)
759 (sb-posix:syscall-errno c
)))
760 (ignore-errors (sb-posix:unlink link-pathname
))))
762 ;; Note: PATH_MAX and NAME_MAX need not be defined, and may vary, so
763 ;; failure of this test is not too meaningful.
764 (deftest readlink.error
.4
766 (make-pathname :name
(make-string 257 ;NAME_MAX plus some, maybe
767 :initial-element
#\a))))
768 (handler-case (sb-posix:readlink pathname
)
769 (sb-posix:syscall-error
(c)
770 (sb-posix:syscall-errno c
))))
771 #.sb-posix
:enametoolong
)
772 (deftest readlink.error
.5
773 (let ((string (format nil
"~v{/A~}" 2049 ;PATH_MAX/2 plus some, maybe
775 (handler-case (sb-posix:readlink string
)
776 (sb-posix:syscall-error
(c)
777 (sb-posix:syscall-errno c
))))
778 #.sb-posix
:enametoolong
)
779 (deftest readlink.error
.6
780 (let ((no-such-pathname (make-pathname :name
"readlink.error.6"
781 :defaults
*test-directory
*)))
782 (handler-case (sb-posix:readlink no-such-pathname
)
783 (sb-posix:syscall-error
(c)
784 (sb-posix:syscall-errno c
))))
786 (deftest readlink.error
.7
787 (let* ((non-link-pathname (make-pathname :name
"readlink.error.7"
788 :defaults
*test-directory
*))
789 (impossible-pathname (merge-pathnames
792 '(:relative
"readlink.error.7")
793 :name
"readlink.error.7")
795 (fd (sb-posix:open non-link-pathname sb-posix
::o-creat
)))
797 (handler-case (sb-posix:readlink impossible-pathname
)
798 (sb-posix:syscall-error
(c)
799 (sb-posix:syscall-errno c
)))
802 (sb-posix:unlink non-link-pathname
))))
807 ;; FIXME: something saner, please
808 (equal (sb-unix::posix-getcwd
) (sb-posix:getcwd
))
813 (multiple-value-bind (fd temp
)
814 (sb-posix:mkstemp
(make-pathname
817 :defaults
*test-directory
*))
818 (let ((pathname (sb-ext:parse-native-namestring temp
)))
820 (values (integerp fd
) (pathname-name pathname
))
821 (delete-file temp
))))
824 ;#-(or win32 sunos hpux)
825 ;;;; mkdtemp is unimplemented on at least Solaris 10
826 #-
(or win32 hpux sunos
)
827 ;;; But it is implemented on OpenSolaris 2008.11
830 (sb-ext:parse-native-namestring
831 (sb-posix:mkdtemp
(make-pathname
834 :defaults
*test-directory
*))
836 *default-pathname-defaults
*
839 (values (let* ((xxx (car (last (pathname-directory pathname
))))
840 (p (position #\. xxx
)))
841 (and p
(subseq xxx
0 p
)))
842 (pathname-name pathname
)
843 (pathname-type pathname
))
844 (sb-posix:rmdir pathname
)))
849 (let ((pathname (sb-ext:parse-native-namestring
850 (sb-posix:mktemp
#p
"mktemp.XXXXXX"))))
851 (values (equal "mktemp" (pathname-name pathname
))
852 (not (equal "XXXXXX" (pathname-type pathname
)))))
856 (deftest mkstemp.null-terminate
857 (let* ((default (make-pathname :directory
'(:absolute
"tmp")))
858 (filename (namestring (make-pathname :name
"mkstemp-1"
861 ;; The magic 64 is the filename length that happens to
862 ;; trigger the no null termination bug at least on my
863 ;; machine on a certain build.
864 (n (- 64 (length (sb-ext:string-to-octets filename
)))))
865 (multiple-value-bind (fd temp
)
866 (sb-posix:mkstemp
(make-pathname
868 :type
(format nil
"~AXXXXXX"
869 (make-string n
:initial-element
#\x
))
872 (values (integerp fd
) (subseq temp
0 (position #\. temp
)))
873 (delete-file temp
))))
877 (let ((name1 "ASLIFJLSDKFJKAHGSDKLJH")
878 (name2 "KJHFKLJDSHIUYHBSDNFCBH"))
879 (values (sb-posix:getenv name1
)
880 (sb-posix:getenv name1
)
882 (sb-posix:putenv
(concatenate 'string name1
"=name1,test1"))
884 (sb-posix:getenv name1
))
886 (sb-posix:setenv name1
"name1,test2" 0)
888 (sb-posix:getenv name1
))
890 (sb-posix:setenv name2
"name2,test1" 0)
892 (sb-posix:getenv name2
))
894 (sb-posix:setenv name2
"name2,test2" 1)
896 (sb-posix:getenv name2
))))