It’s not too difficult to implement, something like that in file.scm:

#>
# define C_mkstemps(buf, extlen) C_fix(mkstemps(C_c_string(buf), 
C_unfix(extlen)))
# define C_close(fd)         C_fix(close(C_unfix(fd)))
<#


(set! create-temporary-file
  (lambda (#!optional (ext "tmp"))
    (##sys#check-string ext 'create-temporary-file)
    (let* ((n (number-of-bytes ext))
           ;; Account for the added dot.
           (n (if (fx= n 0) 0 (fx+ n 1)))
           (pn (make-pathname
                (tempdir)
                (string-append temp-prefix "XXXXXX")
                ext))
           (r (##core#inline "C_mkstemps" (##sys#make-c-string pn 
'create-temporary-file) n)))
      (if (fx= r -1)
          (##sys#signal-hook
           #:file-error 'create-temporary-file
           (##sys#string-append "cannot create temporary file - " strerror)
           pn)
          (begin
            (##core#inline "C_close" r)
            pn)))))

And then of course dig through the respective Windows APIs to make it work 
there:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/mktemp-s-wmktemp-s?view=msvc-170
(Or just keep the current loop on Windows - _wpktemp_s is slightly quirky).

One could also hypothesise that call-with-temporary-file has the right to exist 
as well,
giving access to the port and the underlying fd.

Let’s see what Felix thinks. If he says that either is worth doing, I will be 
happy
to make the patch.

--
Stan


> On 17 Sep 2026, at 20:20, Diego A. Mundo via Chicken-users 
> <[email protected]> wrote:
> 
> 
> On Thursday, September 17th, 2026 at 13:56, Daniel Colascione via 
> Chicken-users <[email protected]> wrote:
> 
>> Why not just use mkstemp on platforms that support it and outsource the 
>> fiddly bits?
> 
> I think the why not may merely be that nobody has prioritized it and actually 
> done the patch yet. I was just looking at what this would entail. We do have 
> a file-mkstemp in (chicken file posix), which is implemented with mkstemp on 
> unix and a custom function on windows, but:
> 
> a) At least the Unix version is currently broken on master, something to do 
> with the new string representation and u8 vectors, though this seems like a 
> simple fix.
> b) This would be a backward-incompatible change, right? Which might be fine, 
> I just don't see that mkstemp has a way to create a temp file with a 
> particular extension. I don't know how many people were using that feature of 
> create-temporary-file.
> 
> Diego
> 


Reply via email to