summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/ref/posix.texi9
-rw-r--r--libguile/posix.c17
-rw-r--r--libguile/posix.h1
3 files changed, 27 insertions, 0 deletions
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index c5106f56f..b237002c7 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -948,6 +948,15 @@ which is usual for ordinary file creation,
@end example
@end deffn
+@deffn {Scheme Procedure} tmpfile
+@deffnx {C Function} scm_tmpfile
+Return an input/output port to a unique temporary file
+named using the path prefix @code{P_tmpdir} defined in
+@file{stdio.h}.
+The file is automatically deleted when the port is closed
+or the program terminates.
+@end deffn
+
@deffn {Scheme Procedure} dirname filename
@deffnx {C Function} scm_dirname (filename)
Return the directory name component of the file name
diff --git a/libguile/posix.c b/libguile/posix.c
index b228925f3..627647824 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1372,6 +1372,23 @@ SCM_DEFINE (scm_mkstemp, "mkstemp!", 1, 0, 0,
}
#undef FUNC_NAME
+SCM_DEFINE (scm_tmpfile, "tmpfile", 0, 0, 0,
+ (void),
+ "Return an input/output port to a unique temporary file\n"
+ "named using the path prefix @code{P_tmpdir} defined in\n"
+ "@file{stdio.h}.\n"
+ "The file is automatically deleted when the port is closed\n"
+ "or the program terminates.")
+#define FUNC_NAME s_scm_tmpfile
+{
+ FILE *rv;
+
+ if (! (rv = tmpfile ()))
+ SCM_SYSERROR;
+ return scm_fdes_to_port (fileno (rv), "w+", SCM_BOOL_F);
+}
+#undef FUNC_NAME
+
SCM_DEFINE (scm_utime, "utime", 1, 5, 0,
(SCM pathname, SCM actime, SCM modtime, SCM actimens, SCM modtimens,
SCM flags),
diff --git a/libguile/posix.h b/libguile/posix.h
index f7a5bb3a0..ac774d33d 100644
--- a/libguile/posix.h
+++ b/libguile/posix.h
@@ -68,6 +68,7 @@ SCM_API SCM scm_uname (void);
SCM_API SCM scm_environ (SCM env);
SCM_API SCM scm_tmpnam (void);
SCM_API SCM scm_mkstemp (SCM tmpl);
+SCM_API SCM scm_tmpfile (void);
SCM_API SCM scm_open_pipe (SCM pipestr, SCM modes);
SCM_API SCM scm_close_pipe (SCM port);
SCM_API SCM scm_utime (SCM pathname, SCM actime, SCM modtime,