Raymond Toy pushed to branch issue-373-handle-temp-files at cmucl / cmucl
Commits:
-
a96bdc2e
by Raymond Toy at 2025-11-13T07:24:54-08:00
3 changed files:
Changes:
| ... | ... | @@ -702,7 +702,7 @@ |
| 702 | 702 | (delete-directory path :recursive t)
|
| 703 | 703 | (delete-file path))))
|
| 704 | 704 | ;; Finally delete the directory.
|
| 705 | - (unix:unix-rmdir (namestring dir))
|
|
| 705 | + (unix:unix-rmdir (namestring dirname))
|
|
| 706 | 706 | (values))
|
| 707 | 707 | |
| 708 | 708 |
| ... | ... | @@ -588,27 +588,14 @@ os_temporary_directory(void) |
| 588 | 588 | * macosx has a secure per-user temporary directory.
|
| 589 | 589 | * Don't cache the result as this is only called once.
|
| 590 | 590 | */
|
| 591 | - int len;
|
|
| 592 | - char *result;
|
|
| 591 | + size_t len;
|
|
| 593 | 592 | char path[PATH_MAX];
|
| 594 | 593 | |
| 595 | - int path_size = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX);
|
|
| 596 | - if (path_size == 0 || path_size > PATH_MAX) {
|
|
| 597 | - strlcpy(path, "/tmp", sizeof(path));
|
|
| 598 | - }
|
|
| 599 | - |
|
| 600 | - /* Append a slash if needed */
|
|
| 601 | - len = strlen(path);
|
|
| 602 | - result = malloc(len + 1);
|
|
| 603 | -
|
|
| 604 | - /* If malloc fails, just return NULL. */
|
|
| 605 | - if (result) {
|
|
| 606 | - strcpy(result, path);
|
|
| 607 | - |
|
| 608 | - if (path[len] != '/') {
|
|
| 609 | - strcat(result, "/");
|
|
| 610 | - }
|
|
| 594 | + len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX);
|
|
| 595 | + if (len == 0 || len > PATH_MAX || (len == PATH_MAX && path[len - 1] != '/')) {
|
|
| 596 | + strlcpy(path, "/tmp/");
|
|
| 597 | + } else if (path[len - 1] != '/') {
|
|
| 598 | + strcat(path, "/");
|
|
| 611 | 599 | }
|
| 612 | -
|
|
| 613 | - return result;
|
|
| 600 | + return strdup(path);
|
|
| 614 | 601 | } |
| ... | ... | @@ -644,26 +644,22 @@ os_temporary_directory(void) |
| 644 | 644 | * If the TMP envvar is set, use that as the temporary directory.
|
| 645 | 645 | * Otherwise, just assume "/tmp" will work.
|
| 646 | 646 | */
|
| 647 | - char *tmp_path = getenv("TMP");
|
|
| 647 | + char *tmp;
|
|
| 648 | + size_t len;
|
|
| 648 | 649 | char *result;
|
| 649 | - int len;
|
|
| 650 | 650 | |
| 651 | - if (tmp_path == NULL) {
|
|
| 652 | - tmp_path = "/tmp";
|
|
| 651 | + tmp = getenv("TMP");
|
|
| 652 | + if (tmp == NULL) {
|
|
| 653 | + return strdup("/tmp/");
|
|
| 653 | 654 | }
|
| 654 | - |
|
| 655 | - /* Append a slash if needed */
|
|
| 656 | - len = strlen(tmp_path);
|
|
| 657 | - result = malloc(len + 1);
|
|
| 658 | - |
|
| 659 | - /* If malloc fails, just return NULL. */
|
|
| 655 | + len = strlen(tmp);
|
|
| 656 | + if (tmp[len] == '/') {
|
|
| 657 | + return strdup(tmp);
|
|
| 658 | + }
|
|
| 659 | + result = malloc(len + 2);
|
|
| 660 | 660 | if (result) {
|
| 661 | - strcpy(result, tmp_path);
|
|
| 662 | - |
|
| 663 | - if (tmp_path[len] != '/') {
|
|
| 664 | - strcat(result, "/");
|
|
| 665 | - }
|
|
| 661 | + sprintf(result, "%s/", tmp);
|
|
| 666 | 662 | }
|
| 667 | -
|
|
| 668 | 663 | return result;
|
| 669 | 664 | }
|
| 665 | +} |