... |
... |
@@ -632,6 +632,19 @@ |
632
|
632
|
(unless (alien:null-alien path)
|
633
|
633
|
(alien:free-alien path)))))
|
634
|
634
|
|
|
635
|
+;; Create a template suitable for mkstemp and mkdtemp. PREFIX is
|
|
636
|
+;; string (or NIL) provided by the macros and is used as is as the
|
|
637
|
+;; template prefix. If PREFIX is NIL, the prefix is obtained by
|
|
638
|
+;; appending DEFAULT-NAME to the OS-dependent temporary path. In all
|
|
639
|
+;; cases, we append exactly 6 X's to create the finale template.
|
|
640
|
+(defun create-template (prefix default-name)
|
|
641
|
+ (concatenate 'string
|
|
642
|
+ (or prefix
|
|
643
|
+ (concatenate 'string
|
|
644
|
+ (get-os-temp-path)
|
|
645
|
+ default-name))
|
|
646
|
+ "XXXXXX"))
|
|
647
|
+
|
635
|
648
|
;;; WITH-TEMPORARY-STREAM -- Public
|
636
|
649
|
;;;
|
637
|
650
|
(defmacro with-temporary-stream ((s &key
|
... |
... |
@@ -641,7 +654,7 @@ |
641
|
654
|
decoding-error
|
642
|
655
|
encoding-error)
|
643
|
656
|
&parse-body (forms decls))
|
644
|
|
- "Return a stream to a temporary file that is automatically created."
|
|
657
|
+ _N"Return a stream to a temporary file that is automatically created."
|
645
|
658
|
(let ((fd (gensym "FD-"))
|
646
|
659
|
(filename (gensym "FILENAME-"))
|
647
|
660
|
(dir (gensym "DIRECTION-"))
|
... |
... |
@@ -652,10 +665,7 @@ |
652
|
665
|
(unless (member ,direction '(:output :io))
|
653
|
666
|
(error ":direction must be one of :output or :io, not ~S"
|
654
|
667
|
,direction))
|
655
|
|
- (let ((,file-template (concatenate 'string
|
656
|
|
- (get-os-temp-path)
|
657
|
|
- "cmucl-temp-stream-"
|
658
|
|
- "XXXXXX"))
|
|
668
|
+ (let ((,file-template (create-template nil "cmucl-temp-stream-"))
|
659
|
669
|
,fd ,filename ,s)
|
660
|
670
|
(unwind-protect
|
661
|
671
|
(progn
|
... |
... |
@@ -689,13 +699,13 @@ |
689
|
699
|
;;; WITH-TEMPORARY-FILE -- Public
|
690
|
700
|
(defmacro with-temporary-file ((filename &key prefix)
|
691
|
701
|
&parse-body (forms decls))
|
|
702
|
+ _N"Creates a temporary file with a name bound to Filename which a
|
|
703
|
+ namestring. If Prefix is not provided, the temporary file is created
|
|
704
|
+ in a OS-dependent location. Otherwise the prefix is used as a prefix
|
|
705
|
+ for the name. On completion, the file is automatically removed."
|
692
|
706
|
(let ((fd (gensym "FD-"))
|
693
|
707
|
(file-template (gensym "TEMP-PATH-")))
|
694
|
|
- `(let ((,file-template (concatenate 'string
|
695
|
|
- (or ,prefix
|
696
|
|
- (get-os-temp-path)
|
697
|
|
- "cmucl-temp-file-")
|
698
|
|
- "XXXXXX"))
|
|
708
|
+ `(let ((,file-template (create-template ,prefix "cmucl-temp-file-"))
|
699
|
709
|
,filename)
|
700
|
710
|
(unwind-protect
|
701
|
711
|
(let (,fd)
|
... |
... |
@@ -715,17 +725,14 @@ |
715
|
725
|
;;; WITH-TEMPORARY-DIRECTORY -- Public
|
716
|
726
|
(defmacro with-temporary-directory ((dirname &key prefix)
|
717
|
727
|
&parse-body (forms decls))
|
718
|
|
- "Return a pathname to a temporary directory. TEMPLATE is a string that
|
719
|
|
- is used as a prefix for the name of the temporary directory. The
|
720
|
|
- directory and all its contents are automatically removed afterward."
|
|
728
|
+ _N"Return a namestring to a temporary directory. If Prefix is not
|
|
729
|
+ provided, the directory is created in an OS-dependent location.
|
|
730
|
+ Otherwise, the Prefix is a string that is used as a prefix for the
|
|
731
|
+ name of the temporary directory. The directory and all its contents
|
|
732
|
+ are automatically removed afterward."
|
721
|
733
|
(let ((err (gensym "ERR-"))
|
722
|
|
- (dir-path (gensym "DIR-PATH"))
|
723
|
734
|
(dir-template (gensym "DIR-TEMPLATE-")))
|
724
|
|
- `(let ((,dir-template (concatenate 'string
|
725
|
|
- (or ,prefix
|
726
|
|
- (get-os-temp-path)
|
727
|
|
- "cmucl-temp-dir-")
|
728
|
|
- "XXXXXX"))
|
|
735
|
+ `(let ((,dir-template (create-template ,prefix "cmucl-temp-dir-"))
|
729
|
736
|
,dirname ,err)
|
730
|
737
|
(unwind-protect
|
731
|
738
|
(progn
|