-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #713 from vyzo/mktemp
Some utilities for working with temporary files
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
;;; -*- Gerbil -*- | ||
;;; © vyzo | ||
;;; [incomplete] OS temporary file interface | ||
|
||
(import :gerbil/gambit/os | ||
:std/foreign | ||
:std/sugar) | ||
(export make-temporary-file-name | ||
call-with-temporary-file-name) | ||
|
||
(def (call-with-temporary-file-name name fun) | ||
(def tmp (make-temporary-file-name name)) | ||
(try | ||
(fun tmp) | ||
(finally | ||
(when (file-exists? tmp) | ||
(delete-file tmp))))) | ||
|
||
(def (make-temporary-file-name name) | ||
(let (tmp (mktemp (string-append "/tmp/" name ".XXXXXX"))) | ||
(when (string-empty? tmp) | ||
(error "Cannot create temporary file" name)) | ||
(string-append tmp "." (number->string (time->seconds (current-time)))))) | ||
|
||
(begin-ffi (mktemp) | ||
(c-declare "#include <stdlib.h>") | ||
(define-c-lambda mktemp (char-string) char-string)) |