Raymond Toy pushed to branch issue-375-mkstemp-return-filename at cmucl / cmucl Commits: 544a6787 by Raymond Toy at 2025-02-01T15:59:09-08:00 Simplify mkdtemp and fix error in mkstemp Since mkdtemp returns a pointer to the resulting directory name, we can convert that to the desired lisp string. In mkstemp, we were converting the resulting buffer to a string but we had `:end (1- length)`. It should be `:end length` to get all the characters. - - - - - 0111bb50 by Raymond Toy at 2025-02-01T16:34:20-08:00 Add tests with template with non-ascii char Add a test for mkstemp and mkdtemp where the template name contains a non-ascii char (lower case alpha) to test the we convert the returned name to a Lisp string correctly. - - - - - 6e0378ea by Raymond Toy at 2025-02-01T16:35:27-08:00 Need to convert the return result of mkdtemp Forgot that we need to encode the result to a proper UTF-16 Lisp string. - - - - - 2 changed files: - src/code/unix.lisp - tests/unix.lisp Changes: ===================================== src/code/unix.lisp ===================================== @@ -2930,7 +2930,7 @@ ;; Convert the array of octets in BUFFER back to ;; a Lisp string. (stream:octets-to-string buffer - :end (1- length) + :end length :external-format format)) (sys:vector-sap buffer)))) @@ -2965,6 +2965,4 @@ ;; resulting name. Otherwise, return NIL and the errno. (if (null-alien result) (values nil (unix-errno)) - (values (stream:octets-to-string buffer - :end (1- length) - :external-format format)))))) + (%file->name (cast result c-call:c-string)))))) ===================================== tests/unix.lisp ===================================== @@ -17,6 +17,26 @@ (when fd (unix:unix-unlink name))))) +(define-test mkstemp.name-returned.2 + (:tag :issues) + (let ((unix::*filename-encoding* :utf-8) + fd name) + (unwind-protect + (progn + ;; Temp name starts with a lower case alpha character. + (let* ((template (concatenate 'string (string #\u+3b1) + "test-XXXXXX")) + (x-posn (position #\X template))) + (multiple-value-setq (fd name) + (unix::unix-mkstemp template)) + (assert-true fd) + (assert-false (search "XXXXXX" name) + name) + (assert-true (string= name template :end1 x-posn :end2 x-posn) + name))) + (when fd + (unix:unix-unlink name))))) + (define-test mkstemp.bad-path (:tag :issues) (multiple-value-bind (fd errno) @@ -52,6 +72,25 @@ (when name (unix:unix-rmdir name))))) +(define-test mkdtemp.name-returned.2 + (:tag :issues) + (let ((unix::*filename-encoding* :utf-8) + name) + (unwind-protect + (progn + ;; Temp name starts with a lower case alpha character. + (let* ((template (concatenate 'string (string #\u+3b1) + "dir-XXXXXX")) + (x-posn (position #\X template))) + (setf name (unix::unix-mkdtemp template)) + ;; Verify that the dir name no longer has X's. + (assert-true (stringp name)) + (assert-false (search "XXXXXX" name)) + (assert-true (string= name template :end1 x-posn :end2 x-posn) + name x-posn))) + (when name + (unix:unix-rmdir name))))) + (define-test mkdtemp.bad-path (:tag :issues) (multiple-value-bind (result errno) View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/15501db4886ad26a943e1c0... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/compare/15501db4886ad26a943e1c0... You're receiving this email because of your account on gitlab.common-lisp.net.