Comment 3 for bug 393104

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

Marking as invalid: I don't think this belongs in SBCL as such.

It seems to me that right choices are:

1. Use OSICAT:WITH-TEMPORARY-FILE or OSICAT:OPEN-TEMPORARY-FILE.

2. Roll your own using SBCL interfaces, for example:

(defun open-temporary-file (&key (element-type 'character) (external-format :default))
  (multiple-value-bind (fd namestring) (sb-posix:mkstemp "/tmp/XXXXXXXXXXXX")
    (handler-case
        (sb-posix:unlink namestring)
      (error (e)
        (sb-posix:close fd)
        (error "Could not unlink created temporary file ~A:~% ~A" namestring e)))
    (sb-sys:make-fd-stream fd
                           :input t :output t
                           :element-type element-type
                           :external-format external-format
                           :auto-close t)))

(let ((f (open-temporary-file)))
  (write-line "foo" f)
  (file-position f :start)
  (read-line f)) ; => "foo", NIL

-- all the APIs here are public (though SB-SYS:MAKE-FD-STREAM isn't documented yet, unfortunately.)

3. If something like the above is wanted in SBCL, I think it belongs in a higher-level contrib akin to Osicat -- say SB-OSI, or something.