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 Apply 3 suggestion(s) to 3 file(s) Co-authored-by: Carl Shapiro <cshapiro@panix.com> - - - - - 3 changed files: - src/code/extensions.lisp - src/lisp/Darwin-os.c - src/lisp/Linux-os.c Changes: ===================================== src/code/extensions.lisp ===================================== @@ -702,7 +702,7 @@ (delete-directory path :recursive t) (delete-file path)))) ;; Finally delete the directory. - (unix:unix-rmdir (namestring dir)) + (unix:unix-rmdir (namestring dirname)) (values)) ===================================== src/lisp/Darwin-os.c ===================================== @@ -588,27 +588,14 @@ os_temporary_directory(void) * macosx has a secure per-user temporary directory. * Don't cache the result as this is only called once. */ - int len; - char *result; + size_t len; char path[PATH_MAX]; - int path_size = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX); - if (path_size == 0 || path_size > PATH_MAX) { - strlcpy(path, "/tmp", sizeof(path)); - } - - /* Append a slash if needed */ - len = strlen(path); - result = malloc(len + 1); - - /* If malloc fails, just return NULL. */ - if (result) { - strcpy(result, path); - - if (path[len] != '/') { - strcat(result, "/"); - } + len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, PATH_MAX); + if (len == 0 || len > PATH_MAX || (len == PATH_MAX && path[len - 1] != '/')) { + strlcpy(path, "/tmp/"); + } else if (path[len - 1] != '/') { + strcat(path, "/"); } - - return result; + return strdup(path); } ===================================== src/lisp/Linux-os.c ===================================== @@ -644,26 +644,22 @@ os_temporary_directory(void) * If the TMP envvar is set, use that as the temporary directory. * Otherwise, just assume "/tmp" will work. */ - char *tmp_path = getenv("TMP"); + char *tmp; + size_t len; char *result; - int len; - if (tmp_path == NULL) { - tmp_path = "/tmp"; + tmp = getenv("TMP"); + if (tmp == NULL) { + return strdup("/tmp/"); } - - /* Append a slash if needed */ - len = strlen(tmp_path); - result = malloc(len + 1); - - /* If malloc fails, just return NULL. */ + len = strlen(tmp); + if (tmp[len] == '/') { + return strdup(tmp); + } + result = malloc(len + 2); if (result) { - strcpy(result, tmp_path); - - if (tmp_path[len] != '/') { - strcat(result, "/"); - } + sprintf(result, "%s/", tmp); } - return result; } +} View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/a96bdc2e50c473356862a8db... -- View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/-/commit/a96bdc2e50c473356862a8db... You're receiving this email because of your account on gitlab.common-lisp.net.