
Raymond Toy pushed to branch issue-373-handle-temp-files at cmucl / cmucl Commits: ade0813f by Raymond Toy at 2025-02-19T13:24:19-08:00 First cut at adding os_temp_path Add os_temp_path to os-common.c to return an appropriate location where temporary files can be placed, depending on the OS. Currently, MacOS, has a special method to return a secure per-user temp directory. For everywhere else, we look at the TMP envvar. If it's not set, we just use "/tmp". Add get-os-temp-path in extensions.lisp to get the temporary path. This is used in the macros, but get-os-temp-path doesn't yet call `os_temp_path`. - - - - - 2 changed files: - src/code/extensions.lisp - src/lisp/os-common.c Changes: ===================================== src/code/extensions.lisp ===================================== @@ -613,6 +613,12 @@ course) change at arbitary times." `(lisp::pointer-hash ,x)) +(alien:def-alien-routine os-temp-path c-call:c-string) + +(defun get-os-temp-path () + "Get a path to an appropriate temporary location from the OS" + "/tmp/") + ;;; WITH-TEMPORARY-STREAM -- Public ;;; (defmacro with-temporary-stream ((s &key @@ -634,7 +640,8 @@ (error ":direction must be one of :output or :io, not ~S" ,direction)) (let ((,file-template (concatenate 'string - "/tmp/cmucl-temp-stream-" + (get-os-temp-path) + "cmucl-temp-stream-" "XXXXXX")) ,fd ,filename ,s) (unwind-protect @@ -673,7 +680,8 @@ (file-template (gensym "TEMP-PATH-"))) `(let ((,file-template (concatenate 'string (or ,prefix - "/tmp/cmucl-temp-file-") + (get-os-temp-path) + "cmucl-temp-file-") "XXXXXX")) ,filename) (unwind-protect @@ -702,7 +710,8 @@ (dir-template (gensym "DIR-TEMPLATE-"))) `(let ((,dir-template (concatenate 'string (or ,prefix - "/tmp/cmucl-temp-dir") + (get-os-temp-path) + "cmucl-temp-dir-") "XXXXXX")) ,dirname ,err) (unwind-protect ===================================== src/lisp/os-common.c ===================================== @@ -936,3 +936,29 @@ os_get_user_homedir(const char* name, int *status) return NULL; } +char * +os_temp_path() +{ +#if defined(DARWIN) + // macosx has a secure per-user temporary directory. + // Don't cache the result as this is only called once. + char path[PATH_MAX]; + char *result; + + int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX); + if (pathSize == 0 || pathSize > PATH_MAX) { + strlcpy(path, "/tmp", sizeof(path)); + } + + return strdup(path); +#else + char *result; + char *tmp_path = getenv("TMP"); + + if (tmp_path == NULL) { + tmp_path = "/tmp"; + } + + return strdup(tmp_path); +#endif +} View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/ade0813f05419c46aad1590d... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/ade0813f05419c46aad1590d... You're receiving this email because of your account on gitlab.common-lisp.net.