[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 01/02: Replace mutating mkdtemp! with non-mutating mkdte

From: Mike Gran
Subject: [Guile-commits] 01/02: Replace mutating mkdtemp! with non-mutating mkdtemp
Date: Thu, 21 Jan 2021 14:37:54 -0500 (EST)

mike121 pushed a commit to branch master
in repository guile.

commit 32bf48e4b799a36276198a70b8ce48740100634e
Author: Michael Gran <>
AuthorDate: Thu Jan 21 09:37:49 2021 -0800

    Replace mutating mkdtemp! with non-mutating mkdtemp
    * doc/ref/posix.texi: replace mkdtemp! and scm_mkdtemp_x documentation
        with documentation for mkdtemp and scm_mkdtemp
    * libguile/filesys.c (scm_mkdtemp_x): procedure mkdtemp! removed
        (scm_mkdtemp): new procedure mkdtemp
    * libguile/filesys.h: Remove declaration for scm_mkdtemp_x.  New declaration
    * test-suite/tests/filesys.test: Remove mkdtemp! tests.  Add tests
        for mkdtemp.
 doc/ref/posix.texi            | 16 ++++++++--------
 libguile/filesys.c            | 24 +++++++++---------------
 libguile/filesys.h            |  2 +-
 test-suite/tests/filesys.test | 37 ++++++++++++++++---------------------
 4 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 8ea5baa..e78e151 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1020,23 +1020,23 @@ The file is automatically deleted when the port is 
 or the program terminates.
 @end deffn
-@deffn {Scheme Procedure} mkdtemp! tmpl
-@deffnx {C Function} scm_mkdtemp_x (tmpl)
+@deffn {Scheme Procedure} mkdtemp tmpl
+@deffnx {C Function} scm_mkdtemp (tmpl)
 @cindex temporary directory
 Create a new directory named in accordance with the template string
 @var{tmpl} is a string specifying the directory's name. The last six
-characters of @var{tmpl} must be @samp{XXXXXX}, characters that will be
-modified to ensure the directory name is unique. Upon successful
-execution, those @samp{X}s will be changed to reflect the name of the
-unique directory created.
+characters of @var{tmpl} must be @samp{XXXXXX}. Upon successful
+execution, the name of the new directory is returned which has the same
+form as @var{tmpl} but with the @samp{XXXXXX} characters modified to
+ensure the directory name is unique.
 The permissions of the directory created are OS dependent, but, are
 usually @code{#o700}.
-The return value is unspecified.  An error may be thrown if the template
-has the wrong format or if the directory cannot be created.
+An error may be thrown if the template has the wrong format or if the
+directory cannot be created.
 @end deffn
 @deffn {Scheme Procedure} dirname filename
diff --git a/libguile/filesys.c b/libguile/filesys.c
index baff7b4..1b0af6e 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1545,41 +1545,35 @@ scm_mkstemp (SCM tmpl)
-SCM_DEFINE (scm_mkdtemp_x, "mkdtemp!", 1, 0, 0,
+SCM_DEFINE (scm_mkdtemp, "mkdtemp", 1, 0, 0,
            (SCM tmpl),
             "Create a new unique directory in the file system named in\n"
-            "accordance with @var{tmpl}. The last 6 characters of the\n"
-            "template must be XXXXXX\n"
+            "accordance with @var{tmpl}. The last six characters of the\n"
+            "template must be 'XXXXXX'.\n"
-            "Upon success, the template string, which must be mutable, will\n"
-            "be modified in place with the name of the directory created.\n"
-            "The return value is unspecified.\n"
+            "Upon success, this procedure returns the name of the\n"
+            "directory created.\n"
             "An error may be thrown if the template is incorrect or if\n"
             "the directory could not be created.\n")
-#define FUNC_NAME s_scm_mkdtemp_x
+#define FUNC_NAME s_scm_mkdtemp
   char *c_tmpl;
   char *rv;
+  SCM new_dirname;
-  /* 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_substring_move_x (scm_from_locale_string (c_tmpl),
-                       SCM_INUM0, scm_string_length (tmpl),
-                       tmpl, SCM_INUM0);
+  new_dirname = scm_from_locale_string (c_tmpl);
   scm_dynwind_end ();
+  return new_dirname;
 #undef FUNC_NAME
 #endif /* HAVE_MKDTEMP */
diff --git a/libguile/filesys.h b/libguile/filesys.h
index 7f8f6ee..a3b257c 100644
--- a/libguile/filesys.h
+++ b/libguile/filesys.h
@@ -66,7 +66,7 @@ SCM_API SCM scm_readlink (SCM path);
 SCM_API SCM scm_lstat (SCM str);
 SCM_API SCM scm_copy_file (SCM oldfile, SCM newfile);
 SCM_API SCM scm_mkstemp (SCM tmpl);
-SCM_API SCM scm_mkdtemp_x (SCM tmpl);
+SCM_API SCM scm_mkdtemp (SCM tmpl);
 SCM_API SCM scm_dirname (SCM filename);
 SCM_API SCM scm_basename (SCM filename, SCM suffix);
 SCM_API SCM scm_canonicalize_path (SCM path);
diff --git a/test-suite/tests/filesys.test b/test-suite/tests/filesys.test
index 8ef4e39..e61b96f 100644
--- a/test-suite/tests/filesys.test
+++ b/test-suite/tests/filesys.test
@@ -233,40 +233,35 @@
   (delete-file (test-symlink)))
-(with-test-prefix "mkdtemp!"
+(with-test-prefix "mkdtemp"
   (pass-if-exception "number arg" exception:wrong-type-arg
-    (if (not (defined? 'mkdtemp!))
+    (if (not (defined? 'mkdtemp))
         (throw 'unresolved)
-        (mkdtemp! 123)))
+        (mkdtemp 123)))
-  (pass-if "directory name template prefix is unmodified"
-    (if (not (defined? 'mkdtemp!))
+  (pass-if "template prefix is preserved"
+    (if (not (defined? 'mkdtemp))
         (throw 'unresolved)
-        (let ((template (string-copy "T-XXXXXX")))
-          (mkdtemp! template)
+        (let* ((template "T-XXXXXX")
+               (name (mkdtemp template)))
           (false-if-exception (rmdir template))
-           (string? template)
-           (string-contains template "T-")
-           (= (string-length template) 8)))))
-  (pass-if-exception "read-only template" exception:miscellaneous-error
-    (if (not (defined? 'mkdtemp!))
-        (throw 'unresolved)
-        (mkdtemp! (substring/read-only "T-XXXXXX" 0))))
+           (string? name)
+           (string-contains name "T-")
+           (= (string-length name) 8)))))
   (pass-if-exception "invalid template" exception:system-error
-    (if (not (defined? 'mkdtemp!))
+    (if (not (defined? 'mkdtemp))
         (throw 'unresolved)
-        (mkdtemp! (string-copy "T-AAAAAA" 0))))
+        (mkdtemp "T-AAAAAA")))
   (pass-if "directory created"
-    (if (not (defined? 'mkdtemp!))
+    (if (not (defined? 'mkdtemp))
         (throw 'unresolved)
-        (let ((template (string-copy "T-XXXXXX")))
-          (mkdtemp! template)
-          (let* ((_stat    (stat template))
+        (let* ((template "T-XXXXXX")
+               (name (mkdtemp template)))
+          (let* ((_stat    (stat name))
                  (result   (eqv? 'directory (stat:type _stat))))
             (false-if-exception (rmdir template))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]