>From 6f5612459b1e414c33b5a1814a5bec57eb81052e Mon Sep 17 00:00:00 2001 From: Thien-Thi Nguyen Date: Fri, 12 Feb 2010 16:01:16 +0100 Subject: [PATCH] Add tmpfile(3) to libguile. * libguile/posix.c (sym_tmpfile): New symbol. (scm_tmpfile): New primitive. * libguile/posix.h (scm_tmpfile): New func decl. * doc/ref/posix.texi (File System): Document `tmpfile'. Signed-off-by: Thien-Thi Nguyen --- doc/ref/posix.texi | 14 ++++++++++++++ libguile/posix.c | 24 ++++++++++++++++++++++++ libguile/posix.h | 1 + 3 files changed, 39 insertions(+), 0 deletions(-) diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 6ff7109..349dcbe 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -948,6 +948,20 @@ which is usual for ordinary file creation, @end example @end deffn address@hidden {Scheme Procedure} tmpfile address@hidden {C Function} scm_tmpfile +Return an input/output port to a unique temporary file +named using the path prefix @code{P_tmpdir} defined in address@hidden +The file is automatically deleted when the port is closed +or the program terminates. + +The name of the temporary file associated with the returned +port is not available to Scheme programs; address@hidden(port-filename (tmpfile))} always returns the +symbol @code{tmpfile}. address@hidden 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 73921a2..363de8c 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1373,6 +1373,30 @@ SCM_DEFINE (scm_mkstemp, "mkstemp!", 1, 0, 0, } #undef FUNC_NAME +SCM_SYMBOL (sym_tmpfile, "tmpfile"); + +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.\n" + "\n" + "The name of the temporary file associated with the returned\n" + "port is not available to Scheme programs;\n" + "@code{(port-filename (tmpfile))} always returns the\n" + "symbol @code{tmpfile}.") +#define FUNC_NAME s_scm_tmpfile +{ + FILE *rv; + + if (! (rv = tmpfile ())) + SCM_SYSERROR; + return scm_fdes_to_port (fileno (rv), "w+", sym_tmpfile); +} +#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 420311e..71c46f2 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, -- 1.6.3.2