Summary

file-mkstemp on windows is broken

Metadata

Description

posixwin.scm file-mkstemp utilizes C_mkstemp which is defined as

#define C_mkstemp(t) C_fix(mktemp(C_c_string(t)))

However mktemp returns a char* pointer to the updated template, not an FD as file-mkstemp expects. It seems that mkstemp() was just changed to mktemp() on Windows without checking if it does the same thing.

In my tests on mingw, the template requires exactly 6 Xs. Otherwise it will return NULL (which is translated to FD 0). On success it returns a pointer which is translated to a nonsense FD.

 #;1> (file-mkstemp "test.XXX")
 0
 "test.960"
 ; 2 values
 #;1> (file-mkstemp "test.XXXXXX")
 2253780
 "test.a01960"
 ; 2 values

I think file-mkstemp should throw unimplemented error on Windows instead. Alternatively it could probably be implemented by using mktemp and file-open with (+ open/creat open/excl) in a loop, but you have to get the permissions right and I'm sure there are even more hairy details.

Changes and comments

[2012-04-19 23:34:40 UTC] zbigniew wrote:

Correction, the template requires 6 or more Xs, and rewrites exactly 6, leaving the rest as X. That is not germane to this discussion though.

[2014-08-02 14:54:24 UTC] sjamaan set milestone to 4.10.0

[2014-08-16 14:13:23 UTC] sjamaan changed status from new to closed

[2014-08-16 14:13:23 UTC] sjamaan set resolution to fixed

[2014-08-16 14:13:23 UTC] sjamaan wrote:

Fixed by ee2bab380aa424c045536bdfc6afb26e172aa504 (master) and 299ae5df0477da1bf498c07a824bc1f4508e0fb2 (stability/4.9.0)