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-lab"))
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 (sb-posix:syscall-errno c
)))
116 (define-eacces-test mkdir.error
.3
117 (let* ((dir (merge-pathnames
118 (make-pathname :directory
'(:relative
"mkdir.error.3"))
120 (dir2 (merge-pathnames
121 (make-pathname :directory
'(:relative
"does-not-exist"))
123 (sb-posix:mkdir dir
0)
125 (sb-posix:mkdir dir2
0)
126 (sb-posix:syscall-error
(c)
128 (sb-posix:syscall-errno c
))
130 (sb-posix:rmdir dir2
)
136 (let ((dne (make-pathname :directory
'(:relative
"rmdir.does-not-exist.1"))))
137 (ensure-directories-exist (merge-pathnames dne
*test-directory
*))
138 (sb-posix:rmdir
(merge-pathnames dne
*test-directory
*)))
142 (let ((dne (make-pathname :directory
'(:relative
"rmdir.does-not-exist.2"))))
143 (ensure-directories-exist (merge-pathnames dne
*test-directory
*))
144 (sb-posix:rmdir
(namestring (merge-pathnames dne
*test-directory
*))))
147 (deftest rmdir.error
.1
148 (let ((dne (make-pathname :directory
'(:relative
"rmdir.dne.error.1"))))
150 (sb-posix:rmdir
(merge-pathnames dne
*test-directory
*))
151 (sb-posix:syscall-error
(c)
152 (sb-posix:syscall-errno c
))))
155 (deftest rmdir.error
.2
157 (sb-posix:rmdir
*this-file
*)
158 (sb-posix:syscall-error
(c)
159 (sb-posix:syscall-errno c
)))
165 (deftest rmdir.error
.3
167 (sb-posix:rmdir
#-win32
"/" #+win32
"C:/")
168 (sb-posix:syscall-error
(c)
169 (sb-posix:syscall-errno c
)))
175 (deftest rmdir.error
.4
176 (let* ((dir (ensure-directories-exist
178 (make-pathname :directory
'(:relative
"rmdir.error.4"))
180 (file (make-pathname :name
"foo" :defaults dir
)))
181 (with-open-file (s file
:direction
:output
:if-exists nil
)
182 (write "" :stream s
))
185 (sb-posix:syscall-error
(c)
188 (let ((errno (sb-posix:syscall-errno c
)))
189 ;; documented by POSIX
190 (or (= errno sb-posix
::eexist
) (= errno sb-posix
::enotempty
))))))
193 (define-eacces-test rmdir.error
.5
194 (let* ((dir (merge-pathnames
195 (make-pathname :directory
'(:relative
"rmdir.error.5"))
197 (dir2 (merge-pathnames
198 (make-pathname :directory
'(:relative
"unremovable"))
200 (sb-posix:mkdir dir
+mode-rwx-all
+)
201 (sb-posix:mkdir dir2
+mode-rwx-all
+)
202 (sb-posix:chmod dir
0)
204 (sb-posix:rmdir dir2
)
205 (sb-posix:syscall-error
(c)
206 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
207 (sb-posix:rmdir dir2
)
209 (sb-posix:syscall-errno c
))
211 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
217 (let* ((stat (sb-posix:stat
*test-directory
*))
218 (mode (sb-posix::stat-mode stat
)))
219 ;; FIXME: Ugly ::s everywhere
220 (logand mode
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
)))
221 #.
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
225 (let* ((stat (sb-posix:stat
"/"))
226 (mode (sb-posix::stat-mode stat
)))
227 ;; it's logically possible for / to be writeable by others... but
228 ;; if it is, either someone is playing with strange security
229 ;; modules or they want to know about it anyway.
230 (logand mode sb-posix
::s-iwoth
))
234 (let* ((now (get-universal-time))
235 ;; FIXME: (encode-universal-time 00 00 00 01 01 1970)
236 (unix-now (- now
2208988800))
237 (stat (sb-posix:stat
*test-directory
*))
238 (atime (sb-posix::stat-atime stat
)))
239 ;; FIXME: breaks if mounted noatime :-(
240 #+nil
(< (- atime unix-now
) 10)
241 (< (- atime unix-now
) 10))
246 (let* ((stat (sb-posix:stat
(make-pathname :directory
'(:absolute
:up
))))
247 (mode (sb-posix::stat-mode stat
)))
248 ;; it's logically possible for / to be writeable by others... but
249 ;; if it is, either someone is playing with strange security
250 ;; modules or they want to know about it anyway.
251 (logand mode sb-posix
::s-iwoth
))
254 ;; Test that stat can take a second argument.
257 (let* ((stat-1 (sb-posix:stat
"/"))
258 (inode-1 (sb-posix:stat-ino stat-1
))
259 (stat-2 (sb-posix:stat
"/bin/sh"
261 (inode-2 (sb-posix:stat-ino stat-2
)))
264 (/= inode-1 inode-2
)))
270 (let* ((stat-1 (sb-posix:stat
"/"))
271 (mode-1 (sb-posix:stat-mode stat-1
))
272 (stat-2 (sb-posix:stat
"C:\\CONFIG.SYS"
274 (mode-2 (sb-posix:stat-mode stat-2
)))
281 ;;; FIXME: add tests for carrying a stat structure around in the
282 ;;; optional argument to SB-POSIX:STAT
284 (deftest stat.error
.1
285 (handler-case (sb-posix:stat
"")
286 (sb-posix:syscall-error
(c)
287 (sb-posix:syscall-errno c
)))
290 (define-eacces-test stat.error
.2
291 (let* ((dir (merge-pathnames
292 (make-pathname :directory
'(:relative
"stat.error.2"))
294 (file (merge-pathnames
295 (make-pathname :name
"unstatable")
297 (sb-posix:mkdir dir
+mode-rwx-all
+)
298 (with-open-file (s file
:direction
:output
)
299 (write "" :stream s
))
300 (sb-posix:chmod dir
0)
303 (sb-posix:syscall-error
(c)
304 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
305 (sb-posix:unlink file
)
307 (sb-posix:syscall-errno c
))
309 (sb-posix:chmod dir
(logior sb-posix
::s-iread sb-posix
::s-iwrite sb-posix
::s-iexec
))
310 (sb-posix:unlink file
)
316 (defmacro with-stat-mode
((mode pathname
) &body body
)
317 (let ((stat (gensym)))
318 `(let* ((,stat
(sb-posix:stat
,pathname
))
319 (,mode
(sb-posix::stat-mode
,stat
)))
322 (defmacro with-lstat-mode
((mode pathname
) &body body
)
323 (let ((stat (gensym)))
324 `(let* ((,stat
(sb-posix:lstat
,pathname
))
325 (,mode
(sb-posix::stat-mode
,stat
)))
329 (with-stat-mode (mode *test-directory
*)
330 (sb-posix:s-isreg mode
))
334 (with-stat-mode (mode *test-directory
*)
335 (sb-posix:s-isdir mode
))
339 (with-stat-mode (mode *test-directory
*)
340 (sb-posix:s-ischr mode
))
344 (with-stat-mode (mode *test-directory
*)
345 (sb-posix:s-isblk mode
))
349 (with-stat-mode (mode *test-directory
*)
350 (sb-posix:s-isfifo mode
))
355 (with-stat-mode (mode *test-directory
*)
356 (sb-posix:s-issock mode
))
361 (let ((link-pathname (make-pathname :name
"stat-mode.7"
362 :defaults
*test-directory
*)))
365 (sb-posix:symlink
*test-directory
* link-pathname
)
366 (with-lstat-mode (mode link-pathname
)
367 (sb-posix:s-islnk mode
)))
368 (ignore-errors (sb-posix:unlink link-pathname
))))
372 (let ((pathname (make-pathname :name
"stat-mode.8"
373 :defaults
*test-directory
*)))
376 (with-open-file (out pathname
:direction
:output
)
377 (write-line "test" out
))
378 (with-stat-mode (mode pathname
)
379 (sb-posix:s-isreg mode
)))
380 (ignore-errors (delete-file pathname
))))
383 ;;; see comment in filename's designator definition, in macros.lisp
384 (deftest filename-designator
.1
385 (let ((file (format nil
"~A/[foo].txt" (namestring *test-directory
*))))
386 ;; creat() with a string as argument
387 (let ((fd (sb-posix:creat file sb-posix
:s-iwrite
)))
390 ;; if this test fails, it will probably be with
391 ;; "System call error 2 (No such file or directory)"
392 (let ((*default-pathname-defaults
* *test-directory
*))
393 (sb-posix:unlink
(car (directory "*.txt")))))
397 (let ((name (merge-pathnames "open-test.txt" *test-directory
*)))
401 (sb-posix:creat name
(logior sb-posix
:s-iwrite sb-posix
:s-iread
)))
402 (let ((fd (sb-posix:open name sb-posix
::o-rdonly
)))
403 (ignore-errors (sb-posix:close fd
))
405 (ignore-errors (sb-posix:unlink name
))))
408 #-hpux
; fix: cant handle c-vargs
409 (deftest open.error
.1
410 (handler-case (sb-posix:open
*test-directory
* sb-posix
::o-wronly
)
411 (sb-posix:syscall-error
(c)
412 (sb-posix:syscall-errno c
)))
418 #-
(or (and x86-64
(or linux sunos
)) win32
)
420 (let ((fd (sb-posix:open
"/dev/null" sb-posix
::o-nonblock
)))
421 (= (sb-posix:fcntl fd sb-posix
::f-getfl
) sb-posix
::o-nonblock
))
423 ;; On AMD64/Linux O_LARGEFILE is always set, even though the whole
424 ;; flag makes no sense.
425 #+(and x86-64
(or linux sunos
))
427 (let ((fd (sb-posix:open
"/dev/null" sb-posix
::o-nonblock
)))
428 (/= 0 (logand (sb-posix:fcntl fd sb-posix
::f-getfl
)
429 sb-posix
::o-nonblock
)))
432 #-
(or hpux win32
) ; fix: cant handle c-vargs
433 (deftest fcntl.flock
.1
434 (locally (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
435 (let ((flock (make-instance 'sb-posix
:flock
436 :type sb-posix
:f-wrlck
437 :whence sb-posix
:seek-set
439 (pathname "fcntl.flock.1")
442 (with-open-file (f pathname
:direction
:output
)
443 (write-line "1234567890" f
)
444 (assert (zerop (sb-posix:fcntl f sb-posix
:f-setlk flock
)))
445 (let ((pid (sb-posix:fork
)))
448 (multiple-value-bind (nope error
)
449 (ignore-errors (sb-posix:fcntl f sb-posix
:f-setlk flock
))
452 (cond ((not (null nope
)) 1)
453 ((= (sb-posix:syscall-errno error
) sb-posix
:eagain
)
456 :recklessly-p t
#| don
't delete the file |
#)))
459 (sb-posix:wexitstatus
461 1 (sb-posix:waitpid pid
0))))
462 (throw 'test nil
))))))
468 (deftest fcntl.flock
.2
469 (locally (declare (sb-ext:muffle-conditions sb-ext
:compiler-note
))
470 (let ((flock (make-instance 'sb-posix
:flock
471 :type sb-posix
:f-wrlck
472 :whence sb-posix
:seek-set
474 (pathname "fcntl.flock.2")
477 (with-open-file (f pathname
:direction
:output
)
478 (write-line "1234567890" f
)
479 (assert (zerop (sb-posix:fcntl f sb-posix
:f-setlk flock
)))
480 (let ((ppid (sb-posix:getpid
))
481 (pid (sb-posix:fork
)))
483 (let ((r (sb-posix:fcntl f sb-posix
:f-getlk flock
)))
486 (cond ((not (zerop r
)) 1)
487 ((= (sb-posix:flock-pid flock
) ppid
) 42)
489 :recklessly-p t
#| don
't delete the file |
#))
492 (sb-posix:wexitstatus
494 1 (sb-posix:waitpid pid
0))))
495 (throw 'test nil
))))))
500 (let ((dir (sb-posix:opendir
"/")))
501 (unwind-protect (sb-alien:null-alien dir
)
502 (unless (sb-alien:null-alien dir
)
503 (sb-posix:closedir dir
))))
507 (let ((dir (sb-posix:opendir
"/")))
510 (loop for dirent
= (sb-posix:readdir dir
)
511 until
(sb-alien:null-alien dirent
)
512 when
(not (stringp (sb-posix:dirent-name dirent
)))
513 do
(return-from dir-loop nil
)
515 (sb-posix:closedir dir
)))
519 (deftest readdir
/dirent-name
520 (let ((dir (sb-posix:opendir
*current-directory
*)))
522 (equal (sort (loop for entry
= (sb-posix:readdir dir
)
523 until
(sb-alien:null-alien entry
)
524 collect
(sb-posix:dirent-name entry
))
526 (sort (append '("." "..")
528 (let ((string (enough-namestring p
*current-directory
*)))
529 (if (pathname-name p
)
531 (subseq string
0 (1- (length string
))))))
532 (directory (make-pathname
535 :defaults
*current-directory
*))))
537 (sb-posix:closedir dir
)))
542 ;; make sure that we found something
543 (not (sb-posix:getpwuid
0))
548 ;; make sure that we found something
549 (not (sb-posix:getpwnam
"root"))
553 (deftest pwent.non-existing
554 ;; make sure that we get something sensible, not an error
555 (handler-case (progn (sb-posix:getpwnam
"almost-certainly-does-not-exist")
562 ;; make sure that we found something
563 (not (sb-posix:getgrgid
0))
568 ;; make sure that we found something
569 (not (sb-posix:getgrnam
"sys"))
573 (deftest grent.non-existing
574 ;; make sure that we get something sensible, not an error
575 (handler-case (progn (sb-posix:getgrnam
"almost-certainly-does-not-exist")
581 ;; Requires root or special group + plus a sensible thing on the port
582 (deftest cfget
/setispeed
.1
583 (with-open-file (s "/dev/ttyS0")
584 (let* ((termios (sb-posix:tcgetattr s
))
585 (old (sb-posix:cfgetispeed termios
))
586 (new (if (= old sb-posix
:b2400
)
589 (sb-posix:cfsetispeed new termios
)
590 (sb-posix:tcsetattr
0 sb-posix
:tcsadrain termios
)
591 (setf termios
(sb-posix:tcgetattr s
))
592 (= new
(sb-posix:cfgetispeed termios
))))
596 ;; Requires root or special group + a sensible thing on the port
597 (deftest cfget
/setospeed
.1
598 (with-open-file (s "/dev/ttyS0" :direction
:output
:if-exists
:append
)
599 (let* ((termios (sb-posix:tcgetattr s
))
600 (old (sb-posix:cfgetospeed termios
))
601 (new (if (= old sb-posix
:b2400
)
604 (sb-posix:cfsetospeed new termios
)
605 (sb-posix:tcsetattr
0 sb-posix
:tcsadrain termios
)
606 (setf termios
(sb-posix:tcgetattr
0))
607 (= new
(sb-posix:cfgetospeed termios
))))
613 (plusp (sb-posix:time
))
618 (let ((file (merge-pathnames #p
"utimes.1" *test-directory
*))
619 (atime (random (1- (expt 2 31))))
620 (mtime (random (1- (expt 2 31)))))
621 (with-open-file (stream file
623 :if-exists
:supersede
624 :if-does-not-exist
:create
)
625 (princ "Hello, utimes" stream
))
626 (sb-posix:utime file atime mtime
)
627 (let* ((stat (sb-posix:stat file
)))
629 (list (= (sb-posix:stat-atime stat
) atime
)
630 (= (sb-posix:stat-mtime stat
) mtime
))))
637 (let ((link-pathname (make-pathname :name
"readlink.1"
638 :defaults
*test-directory
*)))
639 (sb-posix:symlink
"/" link-pathname
)
641 (sb-posix:readlink link-pathname
)
642 (ignore-errors (sb-posix:unlink link-pathname
))))
645 ;; Same thing, but with a very long link target (which doesn't have
646 ;; to exist). This tests the array adjustment in the wrapper,
647 ;; provided that the target's length is long enough.
648 #-hpux
; arg2 to readlink is 80, and arg0 is larger than that
650 (let ((target-pathname (make-pathname
651 :name
(make-string 255 :initial-element
#\a)
652 :directory
'(:absolute
)))
653 (link-pathname (make-pathname :name
"readlink.2"
654 :defaults
*test-directory
*)))
655 (sb-posix:symlink target-pathname link-pathname
)
657 (sb-posix:readlink link-pathname
)
658 (ignore-errors (sb-posix:unlink link-pathname
))))
659 #.
(concatenate 'string
"/" (make-string 255 :initial-element
#\a)))
661 ;; The error tests are in the order of exposition from SUSv3.
662 (deftest readlink.error
.1
663 (let* ((subdir-pathname (merge-pathnames
665 :directory
'(:relative
"readlink.error.1"))
667 (link-pathname (make-pathname :name
"readlink.error.1"
668 :defaults subdir-pathname
)))
669 (sb-posix:mkdir subdir-pathname
#o777
)
670 (sb-posix:symlink
"/" link-pathname
)
671 (sb-posix:chmod subdir-pathname
0)
673 (handler-case (sb-posix:readlink link-pathname
)
674 (sb-posix:syscall-error
(c)
675 (sb-posix:syscall-errno c
)))
677 (sb-posix:chmod subdir-pathname
#o777
)
678 (sb-posix:unlink link-pathname
)
679 (sb-posix:rmdir subdir-pathname
))))
681 (deftest readlink.error
.2
682 (let* ((non-link-pathname (make-pathname :name
"readlink.error.2"
683 :defaults
*test-directory
*))
684 (fd (sb-posix:open non-link-pathname sb-posix
::o-creat
)))
686 (handler-case (sb-posix:readlink non-link-pathname
)
687 (sb-posix:syscall-error
(c)
688 (sb-posix:syscall-errno c
)))
691 (sb-posix:unlink non-link-pathname
))))
693 ;; Skipping EIO, ELOOP
694 (deftest readlink.error
.3
695 (let* ((link-pathname (make-pathname :name
"readlink.error.3"
696 :defaults
*test-directory
*))
697 (bogus-pathname (merge-pathnames
700 :directory
'(:relative
"readlink.error.3"))
702 (sb-posix:symlink link-pathname link-pathname
)
704 (handler-case (sb-posix:readlink bogus-pathname
)
705 (sb-posix:syscall-error
(c)
706 (sb-posix:syscall-errno c
)))
707 (ignore-errors (sb-posix:unlink link-pathname
))))
709 ;; Note: PATH_MAX and NAME_MAX need not be defined, and may vary, so
710 ;; failure of this test is not too meaningful.
711 (deftest readlink.error
.4
713 (make-pathname :name
(make-string 257 ;NAME_MAX plus some, maybe
714 :initial-element
#\a))))
715 (handler-case (sb-posix:readlink pathname
)
716 (sb-posix:syscall-error
(c)
717 (sb-posix:syscall-errno c
))))
718 #.sb-posix
:enametoolong
)
719 (deftest readlink.error
.5
720 (let ((string (format nil
"~v{/A~}" 2049 ;PATH_MAX/2 plus some, maybe
722 (handler-case (sb-posix:readlink string
)
723 (sb-posix:syscall-error
(c)
724 (sb-posix:syscall-errno c
))))
725 #.sb-posix
:enametoolong
)
726 (deftest readlink.error
.6
727 (let ((no-such-pathname (make-pathname :name
"readlink.error.6"
728 :defaults
*test-directory
*)))
729 (handler-case (sb-posix:readlink no-such-pathname
)
730 (sb-posix:syscall-error
(c)
731 (sb-posix:syscall-errno c
))))
733 (deftest readlink.error
.7
734 (let* ((non-link-pathname (make-pathname :name
"readlink.error.7"
735 :defaults
*test-directory
*))
736 (impossible-pathname (merge-pathnames
739 '(:relative
"readlink.error.7")
740 :name
"readlink.error.7")
742 (fd (sb-posix:open non-link-pathname sb-posix
::o-creat
)))
744 (handler-case (sb-posix:readlink impossible-pathname
)
745 (sb-posix:syscall-error
(c)
746 (sb-posix:syscall-errno c
)))
749 (sb-posix:unlink non-link-pathname
))))
754 ;; FIXME: something saner, please
755 (equal (sb-unix::posix-getcwd
) (sb-posix:getcwd
))
760 (multiple-value-bind (fd temp
)
761 (sb-posix:mkstemp
(make-pathname
764 :defaults
*test-directory
*))
765 (let ((pathname (sb-ext:parse-native-namestring temp
)))
767 (values (integerp fd
) (pathname-name pathname
))
768 (delete-file temp
))))
771 ;#-(or win32 sunos hpux)
772 ;;;; mkdtemp is unimplemented on at least Solaris 10
774 ;;; But it is implemented on OpenSolaris 2008.11
777 (sb-ext:parse-native-namestring
778 (sb-posix:mkdtemp
(make-pathname
781 :defaults
*test-directory
*))
783 *default-pathname-defaults
*
786 (values (let* ((xxx (car (last (pathname-directory pathname
))))
787 (p (position #\. xxx
)))
788 (and p
(subseq xxx
0 p
)))
789 (pathname-name pathname
)
790 (pathname-type pathname
))
791 (sb-posix:rmdir pathname
)))
796 (let ((pathname (sb-ext:parse-native-namestring
797 (sb-posix:mktemp
#p
"mktemp.XXXXXX"))))
798 (values (equal "mktemp" (pathname-name pathname
))
799 (not (equal "XXXXXX" (pathname-type pathname
)))))
803 (deftest mkstemp.null-terminate
804 (let* ((default (make-pathname :directory
'(:absolute
"tmp")))
805 (filename (namestring (make-pathname :name
"mkstemp-1"
808 ;; The magic 64 is the filename length that happens to
809 ;; trigger the no null termination bug at least on my
810 ;; machine on a certain build.
811 (n (- 64 (length (sb-ext:string-to-octets filename
)))))
812 (multiple-value-bind (fd temp
)
813 (sb-posix:mkstemp
(make-pathname
815 :type
(format nil
"~AXXXXXX"
816 (make-string n
:initial-element
#\x
))
818 (let ((pathname (sb-ext:parse-native-namestring temp
)))
820 (values (integerp fd
) (pathname-name pathname
))
821 (delete-file temp
)))))
825 (let ((name1 "ASLIFJLSDKFJKAHGSDKLJH")
826 (name2 "KJHFKLJDSHIUYHBSDNFCBH"))
827 (values (sb-posix:getenv name1
)
828 (sb-posix:getenv name1
)
830 (sb-posix:putenv
(concatenate 'string name1
"=name1,test1"))
832 (sb-posix:getenv name1
))
834 (sb-posix:setenv name1
"name1,test2" 0)
836 (sb-posix:getenv name1
))
838 (sb-posix:setenv name2
"name2,test1" 0)
840 (sb-posix:getenv name2
))
842 (sb-posix:setenv name2
"name2,test2" 1)
844 (sb-posix:getenv name2
))))