unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH 1/1] Support mkdtemp via mkdtemp! and scm_mkdtemp
@ 2020-12-30  1:50 Rob Browning
  2020-12-30  8:41 ` Mike Gran
  2020-12-30  8:45 ` [PATCH] New procedure mkdtemp to create unique directory names Mike Gran via Developers list for Guile, the GNU extensibility library
  0 siblings, 2 replies; 8+ messages in thread
From: Rob Browning @ 2020-12-30  1:50 UTC (permalink / raw)
  To: guile-devel

* doc/ref/posix.texi: Document mkdtemp! and scm_mkdtemp.
* libguile/filesys.c: (mkdtemp!, scm_mkdtemp): New functions.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
---

 Proposed for 3.0 and/or 2.2 (current patch is against 3.0).

 doc/ref/posix.texi | 14 ++++++++++++++
 libguile/filesys.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 libguile/posix.h   |  1 +
 3 files changed, 63 insertions(+)

diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index f34c5222d..52c71d193 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1020,6 +1020,20 @@ The file is automatically deleted when the port is closed
 or the program terminates.
 @end deffn
 
+@deffn {Scheme Procedure} mkdtemp! tmpl
+@deffnx {C Function} scm_mkdtemp (tmpl)
+@cindex temporary file
+Create a new unique directory in the file system and return
+its path.
+
+@var{tmpl} is a string specifying where the file should be created: it
+must end with @samp{XXXXXX} and those @samp{X}s will be changed in the
+string to reflect the name of the directory created.
+
+The directory mode will be @code{#o700}, as adjusted by the current
+@code{umask}.
+@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/filesys.c b/libguile/filesys.c
index 39bfd38cc..d3643bdbf 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1544,6 +1544,54 @@ scm_mkstemp (SCM tmpl)
   return scm_i_mkstemp (tmpl, SCM_UNDEFINED);
 }
 
+SCM_INTERNAL SCM scm_i_mkdtemp (SCM);
+SCM_DEFINE (scm_i_mkdtemp, "mkdtemp!", 1, 0, 0,
+	    (SCM tmpl),
+	    "Create a new unique directory in the file system and return\n"
+	    "its path.\n"
+	    "\n"
+	    "@var{tmpl} is a string specifying where the file should be\n"
+	    "created: it must end with @samp{XXXXXX} and those @samp{X}s\n"
+	    "will be changed in the string to reflect the name of the\n"
+            "directory created.\n"
+	    "\n"
+	    "The directory mode will be code{#o700}, as adjusted by the\n"
+            "current @code{umask}.")
+#define FUNC_NAME s_scm_i_mkdtemp
+{
+  char *c_tmpl;
+  char *rv;
+
+  SCM_VALIDATE_STRING (SCM_ARG1, tmpl);
+
+  /* Ensure tmpl is mutable.  */
+  scm_i_string_start_writing (tmpl);
+  scm_i_string_stop_writing ();
+
+  scm_dynwind_begin (0);
+
+  c_tmpl = scm_to_locale_string (tmpl);
+  scm_dynwind_free (c_tmpl);
+  SCM_SYSCALL (rv = mkdtemp (c_tmpl));
+  if (rv == NULL)
+    SCM_SYSERROR;
+
+  scm_substring_move_x (scm_from_locale_string (c_tmpl),
+			SCM_INUM0, scm_string_length (tmpl),
+			tmpl, SCM_INUM0);
+
+  scm_dynwind_end ();
+
+  return tmpl;
+}
+#undef FUNC_NAME
+
+SCM
+scm_mkdtemp (SCM tmpl)
+{
+  return scm_i_mkdtemp (tmpl);
+}
+
 \f
 /* Filename manipulation */
 
diff --git a/libguile/posix.h b/libguile/posix.h
index 1d2e1835e..1ac076a83 100644
--- a/libguile/posix.h
+++ b/libguile/posix.h
@@ -66,6 +66,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_mkdtemp (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);
-- 
2.29.2




^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-01-19 14:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-30  1:50 [PATCH 1/1] Support mkdtemp via mkdtemp! and scm_mkdtemp Rob Browning
2020-12-30  8:41 ` Mike Gran
2020-12-30 23:05   ` Rob Browning
2021-01-05  0:42     ` Rob Browning
2021-01-11 14:04       ` Mike Gran
2021-01-13  0:34         ` Rob Browning
2021-01-19 14:04           ` Mike Gran
2020-12-30  8:45 ` [PATCH] New procedure mkdtemp to create unique directory names Mike Gran via Developers list for Guile, the GNU extensibility library

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).