| ... |
... |
@@ -645,57 +645,6 @@ |
|
645
|
645
|
default-name))
|
|
646
|
646
|
"XXXXXX"))
|
|
647
|
647
|
|
|
648
|
|
-;;; WITH-TEMPORARY-STREAM -- Public
|
|
649
|
|
-;;;
|
|
650
|
|
-(defmacro with-temporary-stream ((s &key
|
|
651
|
|
- (direction :output)
|
|
652
|
|
- (element-type 'base-char)
|
|
653
|
|
- (external-format :default)
|
|
654
|
|
- decoding-error
|
|
655
|
|
- encoding-error)
|
|
656
|
|
- &parse-body (forms decls))
|
|
657
|
|
- _N"Return a stream to a temporary file that is automatically created."
|
|
658
|
|
- (let ((fd (gensym "FD-"))
|
|
659
|
|
- (filename (gensym "FILENAME-"))
|
|
660
|
|
- (dir (gensym "DIRECTION-"))
|
|
661
|
|
- (okay (gensym "OKAY-"))
|
|
662
|
|
- (err (gensym "ERR-"))
|
|
663
|
|
- (file-template (gensym "FILE-TEMPLATE-")))
|
|
664
|
|
- `(progn
|
|
665
|
|
- (unless (member ,direction '(:output :io))
|
|
666
|
|
- (error ":direction must be one of :output or :io, not ~S"
|
|
667
|
|
- ,direction))
|
|
668
|
|
- (let ((,file-template (create-template nil "cmucl-temp-stream-"))
|
|
669
|
|
- ,fd ,filename ,s)
|
|
670
|
|
- (unwind-protect
|
|
671
|
|
- (progn
|
|
672
|
|
- (multiple-value-setq (,fd ,filename)
|
|
673
|
|
- (unix::unix-mkstemp ,file-template))
|
|
674
|
|
- (unless ,fd
|
|
675
|
|
- (error "Unable to create temporary stream at ~S: ~A~%"
|
|
676
|
|
- ,file-template
|
|
677
|
|
- (unix:get-unix-error-msg ,filename)))
|
|
678
|
|
- (let* ((,dir ,direction))
|
|
679
|
|
- (setf ,s (make-fd-stream ,fd
|
|
680
|
|
- :input (member ,dir '(:input :io))
|
|
681
|
|
- :output (member ,dir '(:output :io))
|
|
682
|
|
- :element-type ',element-type
|
|
683
|
|
- :external-format ,external-format
|
|
684
|
|
- :decoding-error ,decoding-error
|
|
685
|
|
- :encoding-error ,encoding-error)))
|
|
686
|
|
- ;; Delete the file; we have an open fd to the file, though.
|
|
687
|
|
- (multiple-value-bind (,okay ,err)
|
|
688
|
|
- (unix::unix-unlink ,filename)
|
|
689
|
|
- (unless ,okay
|
|
690
|
|
- (error "Unable to unlink temporary file ~S: ~A"
|
|
691
|
|
- ,filename (unix:get-unix-error-msg ,err))))
|
|
692
|
|
- (locally ,@decls
|
|
693
|
|
- ,@forms))
|
|
694
|
|
- ;; Close the stream which will close the fd now that we're
|
|
695
|
|
- ;; done.
|
|
696
|
|
- (when ,s
|
|
697
|
|
- (close ,s)))))))
|
|
698
|
|
-
|
|
699
|
648
|
;;; WITH-TEMPORARY-FILE -- Public
|
|
700
|
649
|
(defmacro with-temporary-file ((filename &key prefix)
|
|
701
|
650
|
&parse-body (forms decls))
|