unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Rob Browning <rlb@defaultvalue.org>
To: guile-devel@gnu.org
Subject: [PATCH 1/1] Support mkdtemp via mkdtemp! and scm_mkdtemp
Date: Tue, 29 Dec 2020 19:50:05 -0600	[thread overview]
Message-ID: <20201230015005.335417-1-rlb@defaultvalue.org> (raw)

* 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




             reply	other threads:[~2020-12-30  1:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-30  1:50 Rob Browning [this message]
2020-12-30  8:41 ` [PATCH 1/1] Support mkdtemp via mkdtemp! and scm_mkdtemp 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201230015005.335417-1-rlb@defaultvalue.org \
    --to=rlb@defaultvalue.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).