]> git.seodisparate.com - SimpleArchiver/commitdiff
Fix temp_file setup for v0 file format
authorStephen Seo <seo.disparate@gmail.com>
Thu, 26 Dec 2024 01:50:52 +0000 (10:50 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 26 Dec 2024 01:50:52 +0000 (10:50 +0900)
src/archiver.c

index 3a8775a5c537fc92d5b37e22afecfe829f39e04f..f9ff1ec0e4bee65fb25ac40e8939e714df5fe12b 100644 (file)
@@ -187,28 +187,20 @@ int write_files_fn(void *data, void *ud) {
       }
       __attribute__((cleanup(simple_archiver_helper_cleanup_FILE)))
       FILE *tmp_fd = fopen(temp_filename, "wb");
+      __attribute__((cleanup(cleanup_temp_filename_delete))) void **ptrs_array =
+          malloc(sizeof(void *) * 2);
+      ptrs_array[0] = NULL;
+      ptrs_array[1] = NULL;
       if (!tmp_fd) {
-        fprintf(stderr, "ERROR: Unable to create temp file for compressing!\n");
-#if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN || \
-    SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC ||          \
-    SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX
-        __attribute__((
-            cleanup(simple_archiver_helper_cleanup_malloced))) void *real_cwd =
-            realpath(".", NULL);
-        if (real_cwd) {
-          fprintf(stderr, "Tried to create temp file(s) in \"%s\"!\n",
-                  (char *)real_cwd);
+        tmp_fd = tmpfile();
+        if (!tmp_fd) {
+          fprintf(stderr, "ERROR: Unable to create temp file for compressing!\n");
+          return 1;
         }
-#endif
-        fprintf(stderr,
-                "(Use \"--temp-files-dir <dir>\" to change where to write temp "
-                "files.)\n");
-        return 1;
+      } else {
+        ptrs_array[0] = temp_filename;
+        ptrs_array[1] = &tmp_fd;
       }
-      __attribute__((cleanup(cleanup_temp_filename_delete))) void **ptrs_array =
-          malloc(sizeof(void *) * 2);
-      ptrs_array[0] = temp_filename;
-      ptrs_array[1] = &tmp_fd;
 
       // Handle SIGPIPE.
       signal(SIGPIPE, handle_sig_pipe);