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
2 changed files:
Changes:
... | ... | @@ -613,6 +613,12 @@ |
613 | 613 | course) change at arbitary times."
|
614 | 614 | `(lisp::pointer-hash ,x))
|
615 | 615 | |
616 | +(alien:def-alien-routine os-temp-path c-call:c-string)
|
|
617 | + |
|
618 | +(defun get-os-temp-path ()
|
|
619 | + "Get a path to an appropriate temporary location from the OS"
|
|
620 | + "/tmp/")
|
|
621 | + |
|
616 | 622 | ;;; WITH-TEMPORARY-STREAM -- Public
|
617 | 623 | ;;;
|
618 | 624 | (defmacro with-temporary-stream ((s &key
|
... | ... | @@ -634,7 +640,8 @@ |
634 | 640 | (error ":direction must be one of :output or :io, not ~S"
|
635 | 641 | ,direction))
|
636 | 642 | (let ((,file-template (concatenate 'string
|
637 | - "/tmp/cmucl-temp-stream-"
|
|
643 | + (get-os-temp-path)
|
|
644 | + "cmucl-temp-stream-"
|
|
638 | 645 | "XXXXXX"))
|
639 | 646 | ,fd ,filename ,s)
|
640 | 647 | (unwind-protect
|
... | ... | @@ -673,7 +680,8 @@ |
673 | 680 | (file-template (gensym "TEMP-PATH-")))
|
674 | 681 | `(let ((,file-template (concatenate 'string
|
675 | 682 | (or ,prefix
|
676 | - "/tmp/cmucl-temp-file-")
|
|
683 | + (get-os-temp-path)
|
|
684 | + "cmucl-temp-file-")
|
|
677 | 685 | "XXXXXX"))
|
678 | 686 | ,filename)
|
679 | 687 | (unwind-protect
|
... | ... | @@ -702,7 +710,8 @@ |
702 | 710 | (dir-template (gensym "DIR-TEMPLATE-")))
|
703 | 711 | `(let ((,dir-template (concatenate 'string
|
704 | 712 | (or ,prefix
|
705 | - "/tmp/cmucl-temp-dir")
|
|
713 | + (get-os-temp-path)
|
|
714 | + "cmucl-temp-dir-")
|
|
706 | 715 | "XXXXXX"))
|
707 | 716 | ,dirname ,err)
|
708 | 717 | (unwind-protect
|
... | ... | @@ -936,3 +936,29 @@ os_get_user_homedir(const char* name, int *status) |
936 | 936 | return NULL;
|
937 | 937 | }
|
938 | 938 |
|
939 | +char *
|
|
940 | +os_temp_path()
|
|
941 | +{
|
|
942 | +#if defined(DARWIN)
|
|
943 | + // macosx has a secure per-user temporary directory.
|
|
944 | + // Don't cache the result as this is only called once.
|
|
945 | + char path[PATH_MAX];
|
|
946 | + char *result;
|
|
947 | + |
|
948 | + int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX);
|
|
949 | + if (pathSize == 0 || pathSize > PATH_MAX) {
|
|
950 | + strlcpy(path, "/tmp", sizeof(path));
|
|
951 | + }
|
|
952 | +
|
|
953 | + return strdup(path);
|
|
954 | +#else
|
|
955 | + char *result;
|
|
956 | + char *tmp_path = getenv("TMP");
|
|
957 | + |
|
958 | + if (tmp_path == NULL) {
|
|
959 | + tmp_path = "/tmp";
|
|
960 | + }
|
|
961 | +
|
|
962 | + return strdup(tmp_path);
|
|
963 | +#endif
|
|
964 | +} |