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
))
230 (let* ((stat (sb-posix:stat
*test-directory
*))
231 (mode (sb-posix::stat-mode stat
)))
232 ;; FIXME: Ugly ::s everywhere
233 (logand mode
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
)))
234 #.
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
238 (let* ((stat (sb-posix:stat
"/"))
239 (mode (sb-posix::stat-mode stat
)))
240 ;; it's logically possible for / to be writeable by others... but
241 ;; if it is, either someone is playing with strange security
242 ;; modules or they want to know about it anyway.
243 (logand mode sb-posix
::s-iwoth
))
247 (let* ((now (get-universal-time))
248 ;; FIXME: (encode-universal-time 00 00 00 01 01 1970)
249 (unix-now (- now
2208988800))
250 (stat (sb-posix:stat
*test-directory
*))
251 (atime (sb-posix::stat-atime stat
)))
252 ;; FIXME: breaks if mounted noatime :-(
253 #+nil
(< (- atime unix-now
) 10)
254 (< (- atime unix-now
) 10))
259 (let* ((stat (sb-posix:stat
(make-pathname :directory
'(:absolute
:up
))))
260 (mode (sb-posix::stat-mode stat
)))
261 ;; it's logically possible for / to be writeable by others... but
262 ;; if it is, either someone is playing with strange security
263 ;; modules or they want to know about it anyway.
264 (logand mode sb-posix
::s-iwoth
))
267 ;; Test that stat can take a second argument.
270 (let* ((stat-1 (sb-posix:stat
"/"))
271 (inode-1 (sb-posix:stat-ino stat-1
))
272 (stat-2 (sb-posix:stat
"/bin/sh"
274 (inode-2 (sb-posix:stat-ino stat-2
)))
277 (/= inode-1 inode-2
)))
283 (let ((f (namestring (merge-pathnames "some.file" *test-directory
*))))
284 (close (open f
:if-exists
:append
:if-does-not-exist
:create
))
285 (let* ((stat-1 (sb-posix:stat
"/"))
286 (mode-1 (sb-posix:stat-mode stat-1
))
287 (stat-2 (sb-posix:stat f stat-1
))
288 (mode-2 (sb-posix:stat-mode stat-2
)))
291 (/= mode-1 mode-2
))))
295 ;;; FIXME: add tests for carrying a stat structure around in the
296 ;;; optional argument to SB-POSIX:STAT
298 (deftest stat.error
.1
299 (handler-case (sb-posix:stat
"")
300 (sb-posix:syscall-error
(c)
301 (sb-posix:syscall-errno c
)))
304 (define-eacces-test stat.error
.2
305 (let* ((dir (merge-pathnames
306 (make-pathname :directory
'(:relative
"stat.error.2"))
308 (file (merge-pathnames
309 (make-pathname :name
"unstatable")
311 (sb-posix:mkdir dir
+mode-rwx-all
+)
312 (with-open-file (s file
:direction
:output
)
313 (write "" :stream s
))
314 (sb-posix:chmod dir
0)
317 (sb-posix:syscall-error
(c)
318 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
319 (sb-posix:unlink file
)
321 (sb-posix:syscall-errno c
))
323 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
324 (sb-posix:unlink file
)
330 (defmacro with-stat-mode
((mode pathname
) &body body
)
331 (let ((stat (gensym)))
332 `(let* ((,stat
(sb-posix:stat
,pathname
))
333 (,mode
(sb-posix::stat-mode
,stat
)))
336 (defmacro with-lstat-mode
((mode pathname
) &body body
)
337 (let ((stat (gensym)))
338 `(let* ((,stat
(sb-posix:lstat
,pathname
))
339 (,mode
(sb-posix::stat-mode
,stat
)))
343 (with-stat-mode (mode *test-directory
*)
344 (sb-posix:s-isreg mode
))
348 (with-stat-mode (mode *test-directory
*)
349 (sb-posix:s-isdir mode
))
353 (with-stat-mode (mode *test-directory
*)
354 (sb-posix:s-ischr mode
))
358 (with-stat-mode (mode *test-directory
*)
359 (sb-posix:s-isblk mode
))
363 (with-stat-mode (mode *test-directory
*)
364 (sb-posix:s-isfifo mode
))
369 (with-stat-mode (mode *test-directory
*)
370 (sb-posix:s-issock mode
))
375 (let ((link-pathname (make-pathname :name
"stat-mode.7"
376 :defaults
*test-directory
*)))
379 (sb-posix:symlink
*test-directory
* link-pathname
)
380 (with-lstat-mode (mode link-pathname
)
381 (sb-posix:s-islnk mode
)))
382 (ignore-errors (sb-posix:unlink link-pathname
))))
386 (let ((pathname (make-pathname :name
"stat-mode.8"
387 :defaults
*test-directory
*)))
390 (with-open-file (out pathname
:direction
:output
)
391 (write-line "test" out
))
392 (with-stat-mode (mode pathname
)
393 (sb-posix:s-isreg mode
)))
394 (ignore-errors (delete-file pathname
))))
397 ;;; see comment in filename's designator definition, in macros.lisp
398 (deftest filename-designator
.1
399 (let ((file (format nil
"~A/[foo].txt" (namestring *test-directory
*))))
400 ;; creat() with a string as argument
401 (let ((fd (sb-posix:creat file sb-posix
:s-iwrite
)))
404 ;; if this test fails, it will probably be with
405 ;; "System call error 2 (No such file or directory)"
406 (let ((*default-pathname-defaults
* *test-directory
*))
407 (sb-posix:unlink
(car (directory "*.txt")))))
411 (let ((name (merge-pathnames "open-test.txt" *test-directory
*)))
415 (sb-posix:creat name
(logior sb-posix
:s-iwrite sb-posix
:s-iread
)))
416 (let ((fd (sb-posix:open name sb-posix
::o-rdonly
)))
417 (ignore-errors (sb-posix:close fd
))
419 (ignore-errors (sb-posix:unlink name
))))
422 #-hpux
; fix: cant handle c-vargs
423 (deftest open.error
.1
424 (handler-case (sb-posix:open
*test-directory
* sb-posix
::o-wronly
)
425 (sb-posix:syscall-error
(c)
426 (sb-posix:syscall-errno c
)))
432 #-
(or (and x86-64
(or linux sunos
)) win32
)
434 (let ((fd (sb-posix:open
"/dev/null" sb-posix
::o-nonblock
)))
435 (= (sb-posix:fcntl fd sb-posix
::f-getfl
) sb-posix
::o-nonblock
))
437 ;; On AMD64/Linux O_LARGEFILE is always set, even though the whole
438 ;; flag makes no sense.
439 #+(and x86-64
(or linux sunos
))
441 (let ((fd (sb-posix:open
"/dev/null" sb-posix
::o-nonblock
)))
442 (/= 0 (logand (sb-posix:fcntl fd sb-posix
::f-getfl
)
443 sb-posix
::o-nonblock
)))
446 #-
(or hpux win32 netbsd
) ; fix: cant handle c-vargs
447 (deftest fcntl.flock
.1
448 (locally (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
449 (let ((flock (make-instance 'sb-posix
:flock
450 :type sb-posix
:f-wrlck
451 :whence sb-posix
:seek-set
453 (pathname "fcntl.flock.1")
456 (with-open-file (f pathname
:direction
:output
)
457 (write-line "1234567890" f
)
458 (assert (zerop (sb-posix:fcntl f sb-posix
:f-setlk flock
)))
459 (let ((pid (sb-posix:fork
)))
462 (multiple-value-bind (nope error
)
463 (ignore-errors (sb-posix:fcntl f sb-posix
:f-setlk flock
))
466 (cond ((not (null nope
)) 1)
467 ((= (sb-posix:syscall-errno error
) sb-posix
:eagain
)
470 :abort t
#| don
't delete the file |
#)))
473 (sb-posix:wexitstatus
475 1 (sb-posix:waitpid pid
0))))
476 (throw 'test nil
))))))
482 (deftest fcntl.flock
.2
483 (locally (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
484 (let ((flock (make-instance 'sb-posix
:flock
485 :type sb-posix
:f-wrlck
486 :whence sb-posix
:seek-set
488 (pathname "fcntl.flock.2")
491 (with-open-file (f pathname
:direction
:output
)
492 (write-line "1234567890" f
)
493 (assert (zerop (sb-posix:fcntl f sb-posix
:f-setlk flock
)))
494 (let ((ppid (sb-posix:getpid
))
495 (pid (sb-posix:fork
)))
497 (let ((r (sb-posix:fcntl f sb-posix
:f-getlk flock
)))
500 (cond ((not (zerop r
)) 1)
501 ((= (sb-posix:flock-pid flock
) ppid
) 42)
503 :abort t
#| don
't delete the file |
#))
506 (sb-posix:wexitstatus
508 1 (sb-posix:waitpid pid
0))))
509 (throw 'test nil
))))))
515 (with-open-file (ouf (merge-pathnames "read-test.txt" *test-directory
*)
517 :if-exists
:supersede
518 :if-does-not-exist
:create
)
519 (write-string "foo" ouf
))
520 (let ((fd (sb-posix:open
(merge-pathnames "read-test.txt" *test-directory
*) sb-posix
:o-rdonly
)))
522 (let ((buf (make-array 10 :element-type
'(unsigned-byte 8))))
524 (sb-posix:read fd
(sb-sys:vector-sap buf
) 10)
525 (code-char (aref buf
0))
526 (code-char (aref buf
1))
527 (code-char (aref buf
2))))
528 (sb-posix:close fd
))))
532 (let ((dir (sb-posix:opendir
"/")))
533 (unwind-protect (sb-alien:null-alien dir
)
534 (unless (sb-alien:null-alien dir
)
535 (sb-posix:closedir dir
))))
539 (let ((dir (sb-posix:opendir
"/")))
542 (loop for dirent
= (sb-posix:readdir dir
)
543 until
(sb-alien:null-alien dirent
)
544 when
(not (stringp (sb-posix:dirent-name dirent
)))
545 do
(return-from dir-loop nil
)
547 (sb-posix:closedir dir
)))
551 (deftest readdir
/dirent-name
552 (let ((dir (sb-posix:opendir
*current-directory
*)))
554 (equal (sort (loop for entry
= (sb-posix:readdir dir
)
555 until
(sb-alien:null-alien entry
)
556 collect
(sb-posix:dirent-name entry
))
558 (sort (append '("." "..")
560 (let ((string (enough-namestring p
*current-directory
*)))
561 (if (pathname-name p
)
563 (subseq string
0 (1- (length string
))))))
564 (directory (make-pathname
567 :defaults
*current-directory
*))))
569 (sb-posix:closedir dir
)))
575 (let ((fd (sb-posix:open
(merge-pathnames "write-test.txt" *test-directory
*)
576 (logior sb-posix
:o-creat sb-posix
:o-wronly
)
577 (logior sb-posix
:s-irusr sb-posix
:s-iwusr
)))
580 (let ((buf (coerce "foo" 'simple-base-string
)))
581 (setf retval
(sb-posix:write fd
(sb-sys:vector-sap buf
) 3)))
584 (with-open-file (inf (merge-pathnames "write-test.txt" *test-directory
*)
586 (values retval
(read-line inf
)))))
591 ;; make sure that we found something
592 (not (sb-posix:getpwuid
0))
597 ;; make sure that we found something
598 (not (sb-posix:getpwnam
"root"))
602 (deftest pwent.non-existing
603 ;; make sure that we get something sensible, not an error
604 (handler-case (progn (sb-posix:getpwnam
"almost-certainly-does-not-exist")
611 ;; make sure that we found something
612 (not (sb-posix:getgrgid
0))
617 ;; make sure that we found something
618 (not (sb-posix:getgrnam
"sys"))
622 (deftest grent.non-existing
623 ;; make sure that we get something sensible, not an error
624 (handler-case (progn (sb-posix:getgrnam
"almost-certainly-does-not-exist")
630 ;; Requires root or special group + plus a sensible thing on the port
631 (deftest cfget
/setispeed
.1
632 (with-open-file (s "/dev/ttyS0")
633 (let* ((termios (sb-posix:tcgetattr s
))
634 (old (sb-posix:cfgetispeed termios
))
635 (new (if (= old sb-posix
:b2400
)
638 (sb-posix:cfsetispeed new termios
)
639 (sb-posix:tcsetattr
0 sb-posix
:tcsadrain termios
)
640 (setf termios
(sb-posix:tcgetattr s
))
641 (= new
(sb-posix:cfgetispeed termios
))))
645 ;; Requires root or special group + a sensible thing on the port
646 (deftest cfget
/setospeed
.1
647 (with-open-file (s "/dev/ttyS0" :direction
:output
:if-exists
:append
)
648 (let* ((termios (sb-posix:tcgetattr s
))
649 (old (sb-posix:cfgetospeed termios
))
650 (new (if (= old sb-posix
:b2400
)
653 (sb-posix:cfsetospeed new termios
)
654 (sb-posix:tcsetattr
0 sb-posix
:tcsadrain termios
)
655 (setf termios
(sb-posix:tcgetattr
0))
656 (= new
(sb-posix:cfgetospeed termios
))))
662 (plusp (sb-posix:time
))
667 (let ((file (merge-pathnames #p
"utimes.1" *test-directory
*))
668 (atime (random (1- (expt 2 31))))
669 (mtime (random (1- (expt 2 31)))))
670 (with-open-file (stream file
672 :if-exists
:supersede
673 :if-does-not-exist
:create
)
674 (princ "Hello, utimes" stream
))
675 (sb-posix:utime file atime mtime
)
676 (let* ((stat (sb-posix:stat file
)))
678 (list (= (sb-posix:stat-atime stat
) atime
)
679 (= (sb-posix:stat-mtime stat
) mtime
))))
686 (let ((link-pathname (make-pathname :name
"readlink.1"
687 :defaults
*test-directory
*)))
688 (sb-posix:symlink
"/" link-pathname
)
690 (sb-posix:readlink link-pathname
)
691 (ignore-errors (sb-posix:unlink link-pathname
))))
694 ;; Same thing, but with a very long link target (which doesn't have
695 ;; to exist). This tests the array adjustment in the wrapper,
696 ;; provided that the target's length is long enough.
697 #-hpux
; arg2 to readlink is 80, and arg0 is larger than that
699 (let ((target-pathname (make-pathname
700 :name
(make-string 255 :initial-element
#\a)
701 :directory
'(:absolute
)))
702 (link-pathname (make-pathname :name
"readlink.2"
703 :defaults
*test-directory
*)))
704 (sb-posix:symlink target-pathname link-pathname
)
706 (sb-posix:readlink link-pathname
)
707 (ignore-errors (sb-posix:unlink link-pathname
))))
708 #.
(concatenate 'string
"/" (make-string 255 :initial-element
#\a)))
710 ;; The error tests are in the order of exposition from SUSv3.
711 (deftest readlink.error
.1
712 (let* ((subdir-pathname (merge-pathnames
714 :directory
'(:relative
"readlink.error.1"))
716 (link-pathname (make-pathname :name
"readlink.error.1"
717 :defaults subdir-pathname
)))
718 (sb-posix:mkdir subdir-pathname
#o777
)
719 (sb-posix:symlink
"/" link-pathname
)
720 (sb-posix:chmod subdir-pathname
0)
722 (handler-case (sb-posix:readlink link-pathname
)
723 (sb-posix:syscall-error
(c)
724 (sb-posix:syscall-errno c
)))
726 (sb-posix:chmod subdir-pathname
#o777
)
727 (sb-posix:unlink link-pathname
)
728 (sb-posix:rmdir subdir-pathname
))))
730 (deftest readlink.error
.2
731 (let* ((non-link-pathname (make-pathname :name
"readlink.error.2"
732 :defaults
*test-directory
*))
733 (fd (sb-posix:open non-link-pathname sb-posix
::o-creat
)))
735 (handler-case (sb-posix:readlink non-link-pathname
)
736 (sb-posix:syscall-error
(c)
737 (sb-posix:syscall-errno c
)))
740 (sb-posix:unlink non-link-pathname
))))
742 ;; Skipping EIO, ELOOP
743 (deftest readlink.error
.3
744 (let* ((link-pathname (make-pathname :name
"readlink.error.3"
745 :defaults
*test-directory
*))
746 (bogus-pathname (merge-pathnames
749 :directory
'(:relative
"readlink.error.3"))
751 (sb-posix:symlink link-pathname link-pathname
)
753 (handler-case (sb-posix:readlink bogus-pathname
)
754 (sb-posix:syscall-error
(c)
755 (sb-posix:syscall-errno c
)))
756 (ignore-errors (sb-posix:unlink link-pathname
))))
758 ;; Note: PATH_MAX and NAME_MAX need not be defined, and may vary, so
759 ;; failure of this test is not too meaningful.
760 (deftest readlink.error
.4
762 (make-pathname :name
(make-string 257 ;NAME_MAX plus some, maybe
763 :initial-element
#\a))))
764 (handler-case (sb-posix:readlink pathname
)
765 (sb-posix:syscall-error
(c)
766 (sb-posix:syscall-errno c
))))
767 #.sb-posix
:enametoolong
)
768 (deftest readlink.error
.5
769 (let ((string (format nil
"~v{/A~}" 2049 ;PATH_MAX/2 plus some, maybe
771 (handler-case (sb-posix:readlink string
)
772 (sb-posix:syscall-error
(c)
773 (sb-posix:syscall-errno c
))))
774 #.sb-posix
:enametoolong
)
775 (deftest readlink.error
.6
776 (let ((no-such-pathname (make-pathname :name
"readlink.error.6"
777 :defaults
*test-directory
*)))
778 (handler-case (sb-posix:readlink no-such-pathname
)
779 (sb-posix:syscall-error
(c)
780 (sb-posix:syscall-errno c
))))
782 (deftest readlink.error
.7
783 (let* ((non-link-pathname (make-pathname :name
"readlink.error.7"
784 :defaults
*test-directory
*))
785 (impossible-pathname (merge-pathnames
788 '(:relative
"readlink.error.7")
789 :name
"readlink.error.7")
791 (fd (sb-posix:open non-link-pathname sb-posix
::o-creat
)))
793 (handler-case (sb-posix:readlink impossible-pathname
)
794 (sb-posix:syscall-error
(c)
795 (sb-posix:syscall-errno c
)))
798 (sb-posix:unlink non-link-pathname
))))
803 ;; FIXME: something saner, please
804 (equal (sb-unix::posix-getcwd
) (sb-posix:getcwd
))
809 (multiple-value-bind (fd temp
)
810 (sb-posix:mkstemp
(make-pathname
813 :defaults
*test-directory
*))
814 (let ((pathname (sb-ext:parse-native-namestring temp
)))
816 (values (integerp fd
) (pathname-name pathname
))
817 (delete-file temp
))))
820 ;#-(or win32 sunos hpux)
821 ;;;; mkdtemp is unimplemented on at least Solaris 10
822 #-
(or win32 hpux sunos
)
823 ;;; But it is implemented on OpenSolaris 2008.11
826 (sb-ext:parse-native-namestring
827 (sb-posix:mkdtemp
(make-pathname
830 :defaults
*test-directory
*))
832 *default-pathname-defaults
*
835 (values (let* ((xxx (car (last (pathname-directory pathname
))))
836 (p (position #\. xxx
)))
837 (and p
(subseq xxx
0 p
)))
838 (pathname-name pathname
)
839 (pathname-type pathname
))
840 (sb-posix:rmdir pathname
)))
845 (let ((pathname (sb-ext:parse-native-namestring
846 (sb-posix:mktemp
#p
"mktemp.XXXXXX"))))
847 (values (equal "mktemp" (pathname-name pathname
))
848 (not (equal "XXXXXX" (pathname-type pathname
)))))
852 (deftest mkstemp.null-terminate
853 (let* ((default (make-pathname :directory
'(:absolute
"tmp")))
854 (filename (namestring (make-pathname :name
"mkstemp-1"
857 ;; The magic 64 is the filename length that happens to
858 ;; trigger the no null termination bug at least on my
859 ;; machine on a certain build.
860 (n (- 64 (length (sb-ext:string-to-octets filename
)))))
861 (multiple-value-bind (fd temp
)
862 (sb-posix:mkstemp
(make-pathname
864 :type
(format nil
"~AXXXXXX"
865 (make-string n
:initial-element
#\x
))
868 (values (integerp fd
) (subseq temp
0 (position #\. temp
)))
869 (delete-file temp
))))
873 (let ((name1 "ASLIFJLSDKFJKAHGSDKLJH")
874 (name2 "KJHFKLJDSHIUYHBSDNFCBH"))
875 (values (sb-posix:getenv name1
)
876 (sb-posix:getenv name1
)
878 (sb-posix:putenv
(concatenate 'string name1
"=name1,test1"))
880 (sb-posix:getenv name1
))
882 (sb-posix:setenv name1
"name1,test2" 0)
884 (sb-posix:getenv name1
))
886 (sb-posix:setenv name2
"name2,test1" 0)
888 (sb-posix:getenv name2
))
890 (sb-posix:setenv name2
"name2,test2" 1)
892 (sb-posix:getenv name2
))))