summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Gran <spk121@yahoo.com>2021-01-21 09:37:49 -0800
committerMichael Gran <spk121@yahoo.com>2021-01-21 10:33:08 -0800
commit32bf48e4b799a36276198a70b8ce48740100634e (patch)
tree57cce95d03d785ff6e9b2b54f115ef851698a69a
parentc67cbc501face03ed0a4d1445e196c3893f0fb3d (diff)
downloadguile-32bf48e4b799a36276198a70b8ce48740100634e.tar.gz
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 scm_mkdtemp. * test-suite/tests/filesys.test: Remove mkdtemp! tests. Add tests for mkdtemp.
-rw-r--r--doc/ref/posix.texi16
-rw-r--r--libguile/filesys.c24
-rw-r--r--libguile/filesys.h2
-rw-r--r--test-suite/tests/filesys.test37
4 files changed, 34 insertions, 45 deletions
diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 8ea5baa5c..e78e1510c 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -1020,23 +1020,23 @@ 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_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}.
@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 baff7b4c2..1b0af6e14 100644
--- a/libguile/filesys.c
+++ b/libguile/filesys.c
@@ -1545,41 +1545,35 @@ scm_mkstemp (SCM tmpl)
}
#if HAVE_MKDTEMP
-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"
"\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"
"\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;
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);
+ new_dirname = scm_from_locale_string (c_tmpl);
scm_dynwind_end ();
- return SCM_UNSPECIFIED;
+ return new_dirname;
}
#undef FUNC_NAME
#endif /* HAVE_MKDTEMP */
diff --git a/libguile/filesys.h b/libguile/filesys.h
index 7f8f6ee4e..a3b257c12 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 8ef4e396e..e61b96f6e 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))
(and
- (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))
result)))))