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 "C:/")
173 (sb-posix:syscall-error (c)
175 (sb-posix:syscall-errno c)
182 #.sb-posix::enotempty
185 #-(or darwin 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* ((stat-1 (sb-posix:stat "/"))
284 (mode-1 (sb-posix:stat-mode stat-1))
285 (stat-2 (sb-posix:stat "C:\\pagefile.sys"
287 (mode-2 (sb-posix:stat-mode stat-2)))
294 ;;; FIXME: add tests for carrying a stat structure around in the
295 ;;; optional argument to SB-POSIX:STAT
297 (deftest stat.error.1
298 (handler-case (sb-posix:stat "")
299 (sb-posix:syscall-error (c)
300 (sb-posix:syscall-errno c)))
303 (define-eacces-test stat.error.2
304 (let* ((dir (merge-pathnames
305 (make-pathname :directory '(:relative "stat.error.2"))
307 (file (merge-pathnames
308 (make-pathname :name "unstatable")
310 (sb-posix:mkdir dir +mode-rwx-all+)
311 (with-open-file (s file :direction :output)
312 (write "" :stream s))
313 (sb-posix:chmod dir 0)
316 (sb-posix:syscall-error (c)
317 (sb-posix:chmod dir (logior sb-posix::s-iread sb-posix::s-iwrite sb-posix::s-iexec))
318 (sb-posix:unlink file)
320 (sb-posix:syscall-errno c))
322 (sb-posix:chmod dir (logior sb-posix::s-iread sb-posix::s-iwrite sb-posix::s-iexec))
323 (sb-posix:unlink file)
329 (defmacro with-stat-mode ((mode pathname) &body body)
330 (let ((stat (gensym)))
331 `(let* ((,stat (sb-posix:stat ,pathname))
332 (,mode (sb-posix::stat-mode ,stat)))
335 (defmacro with-lstat-mode ((mode pathname) &body body)
336 (let ((stat (gensym)))
337 `(let* ((,stat (sb-posix:lstat ,pathname))
338 (,mode (sb-posix::stat-mode ,stat)))
342 (with-stat-mode (mode *test-directory*)
343 (sb-posix:s-isreg mode))
347 (with-stat-mode (mode *test-directory*)
348 (sb-posix:s-isdir mode))
352 (with-stat-mode (mode *test-directory*)
353 (sb-posix:s-ischr mode))
357 (with-stat-mode (mode *test-directory*)
358 (sb-posix:s-isblk mode))
362 (with-stat-mode (mode *test-directory*)
363 (sb-posix:s-isfifo mode))
368 (with-stat-mode (mode *test-directory*)
369 (sb-posix:s-issock mode))
374 (let ((link-pathname (make-pathname :name "stat-mode.7"
375 :defaults *test-directory*)))
378 (sb-posix:symlink *test-directory* link-pathname)
379 (with-lstat-mode (mode link-pathname)
380 (sb-posix:s-islnk mode)))
381 (ignore-errors (sb-posix:unlink link-pathname))))
385 (let ((pathname (make-pathname :name "stat-mode.8"
386 :defaults *test-directory*)))
389 (with-open-file (out pathname :direction :output)
390 (write-line "test" out))
391 (with-stat-mode (mode pathname)
392 (sb-posix:s-isreg mode)))
393 (ignore-errors (delete-file pathname))))
396 ;;; see comment in filename's designator definition, in macros.lisp
397 (deftest filename-designator.1
398 (let ((file (format nil "~A/[foo].txt" (namestring *test-directory*))))
399 ;; creat() with a string as argument
400 (let ((fd (sb-posix:creat file sb-posix:s-iwrite)))
403 ;; if this test fails, it will probably be with
404 ;; "System call error 2 (No such file or directory)"
405 (let ((*default-pathname-defaults* *test-directory*))
406 (sb-posix:unlink (car (directory "*.txt")))))
410 (let ((name (merge-pathnames "open-test.txt" *test-directory*)))
414 (sb-posix:creat name (logior sb-posix:s-iwrite sb-posix:s-iread)))
415 (let ((fd (sb-posix:open name sb-posix::o-rdonly)))
416 (ignore-errors (sb-posix:close fd))
418 (ignore-errors (sb-posix:unlink name))))
421 #-hpux ; fix: cant handle c-vargs
422 (deftest open.error.1
423 (handler-case (sb-posix:open *test-directory* sb-posix::o-wronly)
424 (sb-posix:syscall-error (c)
425 (sb-posix:syscall-errno c)))
431 #-(or (and x86-64 (or linux sunos)) win32)
433 (let ((fd (sb-posix:open "/dev/null" sb-posix::o-nonblock)))
434 (= (sb-posix:fcntl fd sb-posix::f-getfl) sb-posix::o-nonblock))
436 ;; On AMD64/Linux O_LARGEFILE is always set, even though the whole
437 ;; flag makes no sense.
438 #+(and x86-64 (or linux sunos))
440 (let ((fd (sb-posix:open "/dev/null" sb-posix::o-nonblock)))
441 (/= 0 (logand (sb-posix:fcntl fd sb-posix::f-getfl)
442 sb-posix::o-nonblock)))
445 #-(or hpux win32) ; fix: cant handle c-vargs
446 (deftest fcntl.flock.1
447 (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
448 (let ((flock (make-instance 'sb-posix:flock
449 :type sb-posix:f-wrlck
450 :whence sb-posix:seek-set
452 (pathname "fcntl.flock.1")
455 (with-open-file (f pathname :direction :output)
456 (write-line "1234567890" f)
457 (assert (zerop (sb-posix:fcntl f sb-posix:f-setlk flock)))
458 (let ((pid (sb-posix:fork)))
461 (multiple-value-bind (nope error)
462 (ignore-errors (sb-posix:fcntl f sb-posix:f-setlk flock))
465 (cond ((not (null nope)) 1)
466 ((= (sb-posix:syscall-errno error) sb-posix:eagain)
469 :recklessly-p t #| don't delete the file |#)))
472 (sb-posix:wexitstatus
474 1 (sb-posix:waitpid pid 0))))
475 (throw 'test nil))))))
481 (deftest fcntl.flock.2
482 (locally (declare (sb-ext:muffle-conditions sb-ext:compiler-note))
483 (let ((flock (make-instance 'sb-posix:flock
484 :type sb-posix:f-wrlck
485 :whence sb-posix:seek-set
487 (pathname "fcntl.flock.2")
490 (with-open-file (f pathname :direction :output)
491 (write-line "1234567890" f)
492 (assert (zerop (sb-posix:fcntl f sb-posix:f-setlk flock)))
493 (let ((ppid (sb-posix:getpid))
494 (pid (sb-posix:fork)))
496 (let ((r (sb-posix:fcntl f sb-posix:f-getlk flock)))
499 (cond ((not (zerop r)) 1)
500 ((= (sb-posix:flock-pid flock) ppid) 42)
502 :recklessly-p t #| don't delete the file |#))
505 (sb-posix:wexitstatus
507 1 (sb-posix:waitpid pid 0))))
508 (throw 'test nil))))))
514 (with-open-file (ouf (merge-pathnames "read-test.txt" *test-directory*)
516 :if-exists :supersede
517 :if-does-not-exist :create)
518 (write-string "foo" ouf))
519 (let ((fd (sb-posix:open (merge-pathnames "read-test.txt" *test-directory*) sb-posix:o-rdonly)))
521 (let ((buf (make-array 10 :element-type '(unsigned-byte 8))))
523 (sb-posix:read fd (sb-sys:vector-sap buf) 10)
524 (code-char (aref buf 0))
525 (code-char (aref buf 1))
526 (code-char (aref buf 2))))
527 (sb-posix:close fd))))
531 (let ((dir (sb-posix:opendir "/")))
532 (unwind-protect (sb-alien:null-alien dir)
533 (unless (sb-alien:null-alien dir)
534 (sb-posix:closedir dir))))
538 (let ((dir (sb-posix:opendir "/")))
541 (loop for dirent = (sb-posix:readdir dir)
542 until (sb-alien:null-alien dirent)
543 when (not (stringp (sb-posix:dirent-name dirent)))
544 do (return-from dir-loop nil)
546 (sb-posix:closedir dir)))
550 (deftest readdir/dirent-name
551 (let ((dir (sb-posix:opendir *current-directory*)))
553 (equal (sort (loop for entry = (sb-posix:readdir dir)
554 until (sb-alien:null-alien entry)
555 collect (sb-posix:dirent-name entry))
557 (sort (append '("." "..")
559 (let ((string (enough-namestring p *current-directory*)))
560 (if (pathname-name p)
562 (subseq string 0 (1- (length string))))))
563 (directory (make-pathname
566 :defaults *current-directory*))))
568 (sb-posix:closedir dir)))
574 (let ((fd (sb-posix:open (merge-pathnames "write-test.txt" *test-directory*)
575 (logior sb-posix:o-creat sb-posix:o-wronly)
576 (logior sb-posix:s-irusr sb-posix:s-iwusr)))
579 (let ((buf (coerce "foo" 'simple-base-string)))
580 (setf retval (sb-posix:write fd (sb-sys:vector-sap buf) 3)))
583 (with-open-file (inf (merge-pathnames "write-test.txt" *test-directory*)
585 (values retval (read-line inf)))))
590 ;; make sure that we found something
591 (not (sb-posix:getpwuid 0))
596 ;; make sure that we found something
597 (not (sb-posix:getpwnam "root"))
601 (deftest pwent.non-existing
602 ;; make sure that we get something sensible, not an error
603 (handler-case (progn (sb-posix:getpwnam "almost-certainly-does-not-exist")
610 ;; make sure that we found something
611 (not (sb-posix:getgrgid 0))
616 ;; make sure that we found something
617 (not (sb-posix:getgrnam "sys"))
621 (deftest grent.non-existing
622 ;; make sure that we get something sensible, not an error
623 (handler-case (progn (sb-posix:getgrnam "almost-certainly-does-not-exist")
629 ;; Requires root or special group + plus a sensible thing on the port
630 (deftest cfget/setispeed.1
631 (with-open-file (s "/dev/ttyS0")
632 (let* ((termios (sb-posix:tcgetattr s))
633 (old (sb-posix:cfgetispeed termios))
634 (new (if (= old sb-posix:b2400)
637 (sb-posix:cfsetispeed new termios)
638 (sb-posix:tcsetattr 0 sb-posix:tcsadrain termios)
639 (setf termios (sb-posix:tcgetattr s))
640 (= new (sb-posix:cfgetispeed termios))))
644 ;; Requires root or special group + a sensible thing on the port
645 (deftest cfget/setospeed.1
646 (with-open-file (s "/dev/ttyS0" :direction :output :if-exists :append)
647 (let* ((termios (sb-posix:tcgetattr s))
648 (old (sb-posix:cfgetospeed termios))
649 (new (if (= old sb-posix:b2400)
652 (sb-posix:cfsetospeed new termios)
653 (sb-posix:tcsetattr 0 sb-posix:tcsadrain termios)
654 (setf termios (sb-posix:tcgetattr 0))
655 (= new (sb-posix:cfgetospeed termios))))
661 (plusp (sb-posix:time))
666 (let ((file (merge-pathnames #p"utimes.1" *test-directory*))
667 (atime (random (1- (expt 2 31))))
668 (mtime (random (1- (expt 2 31)))))
669 (with-open-file (stream file
671 :if-exists :supersede
672 :if-does-not-exist :create)
673 (princ "Hello, utimes" stream))
674 (sb-posix:utime file atime mtime)
675 (let* ((stat (sb-posix:stat file)))
677 (list (= (sb-posix:stat-atime stat) atime)
678 (= (sb-posix:stat-mtime stat) mtime))))
685 (let ((link-pathname (make-pathname :name "readlink.1"
686 :defaults *test-directory*)))
687 (sb-posix:symlink "/" link-pathname)
689 (sb-posix:readlink link-pathname)
690 (ignore-errors (sb-posix:unlink link-pathname))))
693 ;; Same thing, but with a very long link target (which doesn't have
694 ;; to exist). This tests the array adjustment in the wrapper,
695 ;; provided that the target's length is long enough.
696 #-hpux ; arg2 to readlink is 80, and arg0 is larger than that
698 (let ((target-pathname (make-pathname
699 :name (make-string 255 :initial-element #\a)
700 :directory '(:absolute)))
701 (link-pathname (make-pathname :name "readlink.2"
702 :defaults *test-directory*)))
703 (sb-posix:symlink target-pathname link-pathname)
705 (sb-posix:readlink link-pathname)
706 (ignore-errors (sb-posix:unlink link-pathname))))
707 #.(concatenate 'string "/" (make-string 255 :initial-element #\a)))
709 ;; The error tests are in the order of exposition from SUSv3.
710 (deftest readlink.error.1
711 (let* ((subdir-pathname (merge-pathnames
713 :directory '(:relative "readlink.error.1"))
715 (link-pathname (make-pathname :name "readlink.error.1"
716 :defaults subdir-pathname)))
717 (sb-posix:mkdir subdir-pathname #o777)
718 (sb-posix:symlink "/" link-pathname)
719 (sb-posix:chmod subdir-pathname 0)
721 (handler-case (sb-posix:readlink link-pathname)
722 (sb-posix:syscall-error (c)
723 (sb-posix:syscall-errno c)))
725 (sb-posix:chmod subdir-pathname #o777)
726 (sb-posix:unlink link-pathname)
727 (sb-posix:rmdir subdir-pathname))))
729 (deftest readlink.error.2
730 (let* ((non-link-pathname (make-pathname :name "readlink.error.2"
731 :defaults *test-directory*))
732 (fd (sb-posix:open non-link-pathname sb-posix::o-creat)))
734 (handler-case (sb-posix:readlink non-link-pathname)
735 (sb-posix:syscall-error (c)
736 (sb-posix:syscall-errno c)))
739 (sb-posix:unlink non-link-pathname))))
741 ;; Skipping EIO, ELOOP
742 (deftest readlink.error.3
743 (let* ((link-pathname (make-pathname :name "readlink.error.3"
744 :defaults *test-directory*))
745 (bogus-pathname (merge-pathnames
748 :directory '(:relative "readlink.error.3"))
750 (sb-posix:symlink link-pathname link-pathname)
752 (handler-case (sb-posix:readlink bogus-pathname)
753 (sb-posix:syscall-error (c)
754 (sb-posix:syscall-errno c)))
755 (ignore-errors (sb-posix:unlink link-pathname))))
757 ;; Note: PATH_MAX and NAME_MAX need not be defined, and may vary, so
758 ;; failure of this test is not too meaningful.
759 (deftest readlink.error.4
761 (make-pathname :name (make-string 257 ;NAME_MAX plus some, maybe
762 :initial-element #\a))))
763 (handler-case (sb-posix:readlink pathname)
764 (sb-posix:syscall-error (c)
765 (sb-posix:syscall-errno c))))
766 #.sb-posix:enametoolong)
767 (deftest readlink.error.5
768 (let ((string (format nil "~v{/A~}" 2049 ;PATH_MAX/2 plus some, maybe
770 (handler-case (sb-posix:readlink string)
771 (sb-posix:syscall-error (c)
772 (sb-posix:syscall-errno c))))
773 #.sb-posix:enametoolong)
774 (deftest readlink.error.6
775 (let ((no-such-pathname (make-pathname :name "readlink.error.6"
776 :defaults *test-directory*)))
777 (handler-case (sb-posix:readlink no-such-pathname)
778 (sb-posix:syscall-error (c)
779 (sb-posix:syscall-errno c))))
781 (deftest readlink.error.7
782 (let* ((non-link-pathname (make-pathname :name "readlink.error.7"
783 :defaults *test-directory*))
784 (impossible-pathname (merge-pathnames
787 '(:relative "readlink.error.7")
788 :name "readlink.error.7")
790 (fd (sb-posix:open non-link-pathname sb-posix::o-creat)))
792 (handler-case (sb-posix:readlink impossible-pathname)
793 (sb-posix:syscall-error (c)
794 (sb-posix:syscall-errno c)))
797 (sb-posix:unlink non-link-pathname))))
802 ;; FIXME: something saner, please
803 (equal (sb-unix::posix-getcwd) (sb-posix:getcwd))
808 (multiple-value-bind (fd temp)
809 (sb-posix:mkstemp (make-pathname
812 :defaults *test-directory*))
813 (let ((pathname (sb-ext:parse-native-namestring temp)))
815 (values (integerp fd) (pathname-name pathname))
816 (delete-file temp))))
819 ;#-(or win32 sunos hpux)
820 ;;;; mkdtemp is unimplemented on at least Solaris 10
821 #-(or win32 hpux sunos)
822 ;;; But it is implemented on OpenSolaris 2008.11
825 (sb-ext:parse-native-namestring
826 (sb-posix:mkdtemp (make-pathname
829 :defaults *test-directory*))
831 *default-pathname-defaults*
834 (values (let* ((xxx (car (last (pathname-directory pathname))))
835 (p (position #\. xxx)))
836 (and p (subseq xxx 0 p)))
837 (pathname-name pathname)
838 (pathname-type pathname))
839 (sb-posix:rmdir pathname)))
844 (let ((pathname (sb-ext:parse-native-namestring
845 (sb-posix:mktemp #p"mktemp.XXXXXX"))))
846 (values (equal "mktemp" (pathname-name pathname))
847 (not (equal "XXXXXX" (pathname-type pathname)))))
851 (deftest mkstemp.null-terminate
852 (let* ((default (make-pathname :directory '(:absolute "tmp")))
853 (filename (namestring (make-pathname :name "mkstemp-1"
856 ;; The magic 64 is the filename length that happens to
857 ;; trigger the no null termination bug at least on my
858 ;; machine on a certain build.
859 (n (- 64 (length (sb-ext:string-to-octets filename)))))
860 (multiple-value-bind (fd temp)
861 (sb-posix:mkstemp (make-pathname
863 :type (format nil "~AXXXXXX"
864 (make-string n :initial-element #\x))
867 (values (integerp fd) (subseq temp 0 (position #\. temp)))
868 (delete-file temp))))
872 (let ((name1 "ASLIFJLSDKFJKAHGSDKLJH")
873 (name2 "KJHFKLJDSHIUYHBSDNFCBH"))
874 (values (sb-posix:getenv name1)
875 (sb-posix:getenv name1)
877 (sb-posix:putenv (concatenate 'string name1 "=name1,test1"))
879 (sb-posix:getenv name1))
881 (sb-posix:setenv name1 "name1,test2" 0)
883 (sb-posix:getenv name1))
885 (sb-posix:setenv name2 "name2,test1" 0)
887 (sb-posix:getenv name2))
889 (sb-posix:setenv name2 "name2,test2" 1)
891 (sb-posix:getenv name2))))