~ chicken-core (master) f192edb20464f98947d6cdf88d79fe2f9d1342d9


commit f192edb20464f98947d6cdf88d79fe2f9d1342d9
Author:     Felix Winkelmann <felix.winkelmann@bevuta.com>
AuthorDate: Thu Sep 17 22:41:46 2026 +0200
Commit:     Felix Winkelmann <felix.winkelmann@bevuta.com>
CommitDate: Thu Sep 17 22:41:46 2026 +0200

    fix buffer handling in file-mkstemp

diff --git a/posixunix.scm b/posixunix.scm
index 885f2068..eea81b24 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -391,12 +391,17 @@ static int set_file_mtime(C_word filename, C_word atime, C_word mtime)
 (set! chicken.file.posix#file-mkstemp
   (lambda (template)
     (##sys#check-string template 'file-mkstemp)
-    (let* ([buf (##sys#make-c-string template 'file-mkstemp)]
-	   [fd (##core#inline "C_mkstemp" buf)]
-	   [path-length (string-length buf)])
-      (when (eq? -1 fd)
-	(posix-error #:file-error 'file-mkstemp "cannot create temporary file" template) )
-      (values fd (##sys#substring buf 0 (fx- path-length 1) ) ) ) ) )
+    (let* ((bv1 (##sys#make-c-string template 'file-mkstemp))
+           (len (##sys#size bv1))
+           (bv2 (##sys#make-bytevector len)) )
+      (##core#inline "C_copy_memory" bv2 bv1 len)
+      (let ((fd (##core#inline "C_mkstemp" bv2)))
+        (when (eq? -1 fd)
+	  (posix-error #:file-error 'file-mkstemp 
+                       "cannot create temporary file" template) )
+        (values 
+          fd 
+          (##sys#buffer->string! bv2 (fx- len 1)))))))
 
 
 ;;; I/O multiplexing:
Trap