Opened 12 years ago

Closed 10 years ago

#819 closed defect (fixed)

file-mkstemp on windows is broken

Reported by: Jim Ursetto Owned by:
Priority: minor Milestone: 4.10.0
Component: core libraries Version: 4.7.x
Keywords: Cc:
Estimated difficulty:


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")
; 2 values
#;1> (file-mkstemp "test.XXXXXX")
; 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.

Change History (3)

comment:1 Changed 12 years ago by Jim Ursetto

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.

comment:2 Changed 10 years ago by sjamaan

Milestone: 4.10.0

comment:3 Changed 10 years ago by sjamaan

Resolution: fixed
Status: newclosed

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

Note: See TracTickets for help on using tickets.