shithub: rgbds

Download patch

ref: 0ed8d3859df61c38e8cecd2612741bdcd71467b4
parent: 632bc2aaecc05590502e9bda1e76f8fac38f2c8b
parent: 1ca59f25d00f626122cc9f7a5095f676959f1266
author: Eldred Habert <[email protected]>
date: Tue Feb 11 03:32:27 EST 2020

Merge pull request #481 from rednex/revert-451-atomic_output

Revert "Make RGBASM overwrite output files atomically"

--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -16,24 +16,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <libgen.h>
 
-#ifdef _WIN32
-#include <windows.h>
-#include <winbase.h>
-/*
- * The semantics of `rename` on Windows differ from POSIX in that it errors out
- * when the target file exists, instead of overwriting it.
- * Thus, shim `rename` with similar semantics (note that the return value of
- * `MoveFileExA` is inverted, and it uses `GetLastError` instead of `errno`)
- */
-#define rename(oldname, newname) \
-	MoveFileExA(oldname, newname, MOVEFILE_WRITE_THROUGH | \
-				      MOVEFILE_REPLACE_EXISTING) \
-	? 0 : (errno = GetLastError(), -1)
-#endif
-
 #include "asm/asm.h"
 #include "asm/charmap.h"
 #include "asm/fstack.h"
@@ -548,25 +531,13 @@
  */
 void out_WriteObject(void)
 {
-	/* Write to a temporary file in the target's folder */
-	char *objectNameCopy = strdup(tzObjectname);
-	char const *dirPath = dirname(objectNameCopy);
-	char tmpFileName[strlen(dirPath) + 1 + 16 + 1];
-
-	sprintf(tmpFileName, "%s/rgbasm_tmpXXXXXX", dirPath);
-	free(objectNameCopy);
-	int fd = mkstemp(tmpFileName);
-
 	FILE *f;
 	struct PatchSymbol *pSym;
 	struct Section *pSect;
 
-	if (fd == -1)
-		err(1, "Couldn't create temporary file");
-
 	addexports();
 
-	f = fdopen(fd, "wb");
+	f = fopen(tzObjectname, "wb");
 	if (f == NULL)
 		fatalerror("Couldn't write file '%s'\n", tzObjectname);
 
@@ -589,11 +560,6 @@
 	}
 
 	fclose(f);
-	close(fd);
-
-	if (rename(tmpFileName, tzObjectname) != 0)
-		err(1, "Couldn't create object file (temp file kept as %s)",
-		    tmpFileName);
 }
 
 /*