summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/txr/stdlib/doc-syms.tl1
-rw-r--r--stream.c12
-rw-r--r--stream.h1
-rw-r--r--txr.126
4 files changed, 40 insertions, 0 deletions
diff --git a/share/txr/stdlib/doc-syms.tl b/share/txr/stdlib/doc-syms.tl
index 396905dd..223eb987 100644
--- a/share/txr/stdlib/doc-syms.tl
+++ b/share/txr/stdlib/doc-syms.tl
@@ -1861,6 +1861,7 @@
("time-t" "N-03258244")
("time-usec" "N-03B6DB3D")
("time-utc" "N-001284ED")
+ ("tmpfile" "N-00FF7C41")
("tnode" "N-0008DDFB")
("tnodep" "N-00D8534F")
("to" "N-00AED1A7")
diff --git a/stream.c b/stream.c
index f24f7eff..14e1f725 100644
--- a/stream.c
+++ b/stream.c
@@ -4941,6 +4941,17 @@ val make_byte_input_stream(val obj)
}
}
+val tmpfile_wrap(void)
+{
+ struct stdio_mode m_blank = stdio_mode_init_blank;
+ struct stdio_mode m = do_parse_mode(lit("w+b"), m_blank);
+ FILE *tf = tmpfile();
+ if (tf != 0)
+ return set_mode_props(m, make_stdio_stream(tf, lit("tmpfile")));
+ uw_throwf(file_error_s, lit("tmpnam failed: ~d/~s"),
+ num(errno), errno_to_str(errno), nao);
+}
+
static val iobuf_free_list;
val iobuf_get(void)
@@ -5133,6 +5144,7 @@ void stream_init(void)
reg_varl(intern(lit("indent-data"), user_package), num_fast(indent_data));
reg_varl(intern(lit("indent-code"), user_package), num_fast(indent_code));
reg_varl(intern(lit("indent-foff"), user_package), num_fast(indent_foff));
+ reg_fun(intern(lit("tmpfile"), user_package), func_n0(tmpfile_wrap));
#if HAVE_SOCKETS
uw_register_subtype(socket_error_s, error_s);
diff --git a/stream.h b/stream.h
index 6d84f7a0..8e6874dc 100644
--- a/stream.h
+++ b/stream.h
@@ -251,4 +251,5 @@ val make_byte_input_stream(val obj);
val iobuf_get(void);
void iobuf_put(val buf);
void iobuf_list_empty(void);
+val tmpfile_wrap(void);
void stream_init(void);
diff --git a/txr.1 b/txr.1
index dbe30aac..6da4c92e 100644
--- a/txr.1
+++ b/txr.1
@@ -55022,6 +55022,32 @@ and
.code ..
entries in Unix filesystems are not skipped.
+.coNP Function @ tmpfile
+.synb
+.mets (tmpfile)
+.syne
+.desc
+The
+.code tmpfile
+function creates a new temporary binary file which is different from any
+existing file. It opens a stream for that file and returns the stream. The
+stream is created with the
+.code open-file
+mode
+.strn w+b .
+When the stream is closed, or the \*(TX image terminates, the file is deleted.
+
+Note: the
+.code tmpfile
+function is implemented using the same-named ISO C and POSIX library function.
+On POSIX systems of sufficient quality,
+.code tmpfile
+deletes the file before returning the open stream, such that the file object
+continues to exist while the stream is open, but is not known by any name
+in the file system. POSIX (IEEE Std 1003.1-2017) notes that in some
+implementations, "a permanent file may be left behind if the process calling
+tmpfile() is killed while it is processing a call to tmpfile".
+
.coNP Function @ make-string-input-stream
.synb
.mets (make-string-input-stream << string )