[m-rev.] diff: Fix mkstemp/mkdtemp implementations of make_temp_file/directory.

Peter Wang novalazy at gmail.com
Thu Oct 6 17:57:40 AEDT 2016


Perhaps we should delete the Suffix argument now?

---

Fix mkstemp/mkdtemp implementations of make_temp_file/directory.

library/io.m:
    Ignore Suffix in mkstemp/mkdtemp implementations of `make_temp_file/6'
    and `make_temp_directory/6'. The last six characters of the template
    argument to mkstemp/mkdtemp can only be be "XXXXXX"; appending a
    non-empty Suffix causes the functions to fail.

    Update documentation.

diff --git a/library/io.m b/library/io.m
index b11293a..7c313eb 100644
--- a/library/io.m
+++ b/library/io.m
@@ -1340,12 +1340,15 @@
 :- pragma obsolete(make_temp/3).
 :- pred make_temp(string::out, io::di, io::uo) is det.
 
-    % make_temp(Dir, Prefix, Suffix, Result, !IO) creates an empty file whose
-    % name is different to the name of any existing file. The file will reside
-    % in the directory specified by Dir and will have a prefix using up to
-    % the first 5 characters of Prefix. If successful, Result returns the name
-    % of the file.  It is the responsibility of the caller to delete the file
-    % when it is no longer required.
+    % make_temp_file(Dir, Prefix, Suffix, Result, !IO) creates an empty file
+    % whose name is different to the name of any existing file. The file will
+    % reside in the directory specified by Dir and will have a prefix using up
+    % to the first 5 characters of Prefix. If successful, Result returns the
+    % name of the file. It is the responsibility of the caller to delete the
+    % file when it is no longer required.
+    %
+    % The C backend has the following limitations:
+    %   - Suffix may be ignored.
     %
     % The C# backend has the following limitations:
     %   - Dir is ignored.
@@ -1384,6 +1387,9 @@
     % new directory. It is the responsibility of the program to delete the
     % directory when it is no longer needed.
     %
+    % The C backend has the following limitations:
+    %   - Suffix is ignored.
+    %
     % The C# backend has the following limitations:
     %   - Prefix is ignored.
     %   - Suffix is ignored.
@@ -10439,8 +10445,12 @@ import java.util.Random;
 #ifdef MR_HAVE_MKSTEMP
     int err, fd;
 
-    FileName = MR_make_string(MR_ALLOC_ID, ""%s%s%.5sXXXXXX%s"",
-        Dir, Sep, Prefix, Suffix);
+    /*
+    ** We cannot append Suffix because the last six chars in the argument
+    ** to mkstemp() must be XXXXXX.
+    */
+    FileName = MR_make_string(MR_ALLOC_ID, ""%s%s%.5sXXXXXX"",
+        Dir, Sep, Prefix);
     fd = mkstemp(FileName);
     if (fd == -1) {
         ML_make_err_msg(errno, ""error opening temporary file: "", MR_ALLOC_ID,
@@ -10659,8 +10669,12 @@ import java.util.Random;
 #ifdef MR_HAVE_MKDTEMP
     int err;
 
-    DirName = MR_make_string(MR_ALLOC_ID, ""%s%s%.5sXXXXXX%s"",
-        Dir, Sep, Prefix, Suffix);
+    /*
+    ** We cannot append Suffix because the last six chars in the argument
+    ** to mkdtemp() must be XXXXXX.
+    */
+    DirName = MR_make_string(MR_ALLOC_ID, ""%s%s%.5sXXXXXX"",
+        Dir, Sep, Prefix);
     DirName = mkdtemp(DirName);
     if (DirName == NULL) {
         ML_make_err_msg(errno, ""error creating temporary directory: "",



More information about the reviews mailing list