() Andy Wingo <wi...@pobox.com>
() Wed, 10 Feb 2010 00:17:30 +0100

   Yes, I think that's probably the right answer.

On the (faint) suspicion that `scm_fdes_to_port' does not DTRT, given
the file descriptor extracted via `fileno' from the `FILE *', i ran a
small test:

 (write (getpid)) (newline)
 (define tmp (tmpfile))
 (sleep 10)
 (set! tmp #f) ; lose ref
 (let loop () (gc) (sleep 1) (loop))

and monitored using "watch lsof -p PID".  I observed that the descriptor
is listed as "/tmp/FILENAME (deleted)" from the beginning and that after
some time, this entry goes away.  So my trust in `scm_fdes_to_port' is
not broken (cool).  Still, i wonder what others see.

   Yes, this sounds better than mkstemp!. Since you seem to have to code
   already, can you submit two patches with mkstemp and tempfile,
   respectively?

I think you mean `tmpfile'.  Please see attached patch.

   While we're here... Ludovic, Neil and I talked over mail about your
   request to (re)join the Guile project, and we're very happy to have
   your skills and energy.  The one concern that we have is that you
   tend to be a bit cavalier; so until we feel like we're on the same
   page, we would like for you to refrain from committing to master or
   the 1.8 branch.

Thanks for the frank assessment.  I will try to be less cavalier (or
perhaps more "anti-cavalier", once i figure out what that means in this
context).  I appreciate any tips on this aspect.

   Instead, please feel free to (commit to | create) other branches in
   the repository, preferably prefixing those branches with "wip-" if
   you intend them to be rebased at some point.  Please mail the list
   when you would like for us to review and merge your patches into
   master or 1.8.

OK.  How do you feel about a branches named ttn/wip-TOPIC ?

   I recognize that it's a somewhat awkward situation, but we're so
   unfamiliar with each other at this point that a slow rapprochement
   would probably be best to avoid unexpected conflicts.

Agreed.

   That said, welcome back to Guile!

Thanks for giving me another chance.  Perhaps i can avoid squandering
the privelege as i did the previous time.

thi


____________________________________________________
>From 6f5612459b1e414c33b5a1814a5bec57eb81052e Mon Sep 17 00:00:00 2001
From: Thien-Thi Nguyen <t...@gnuvola.org>
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 <t...@gnuvola.org>
---
 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
 
+...@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.
+
+The name of the temporary file associated with the returned
+port is not available to Scheme programs;
+...@code{(port-filename (tmpfile))} always returns the
+symbol @code{tmpfile}.
+...@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 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

Reply via email to