From bec75d9e62122e562931b4e41b164b3003ddaf12 Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Sun, 9 Feb 2014 01:11:11 +0100
Subject: [PATCH] Avoid tmpfile().
- tmpfile() tries to create files in the C: root dir on Windows where users usually don't have access.
- tmpnam() uses the curent dir which doesn't seem to be a good idea either.
- tempnam(NULL,NULL) is supposed to be cleverer.
---
src/ar65.vcxproj | 4 ++--
src/ar65/library.c | 17 ++++++++++++++---
src/ar65/library.h | 3 ---
src/ca65.vcxproj | 4 ++--
src/cc65.vcxproj | 4 ++--
src/cl65.vcxproj | 4 ++--
src/co65.vcxproj | 4 ++--
src/common.vcxproj | 4 ++--
src/da65.vcxproj | 4 ++--
src/grc65.vcxproj | 4 ++--
src/ld65.vcxproj | 4 ++--
src/od65.vcxproj | 4 ++--
src/sim65.vcxproj | 4 ++--
src/sp65.vcxproj | 4 ++--
14 files changed, 38 insertions(+), 30 deletions(-)
diff --git a/src/ar65.vcxproj b/src/ar65.vcxproj
index e83f0f984..baf3efd6b 100644
--- a/src/ar65.vcxproj
+++ b/src/ar65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/ar65/library.c b/src/ar65/library.c
index 9046e315f..1f8a2425e 100644
--- a/src/ar65/library.c
+++ b/src/ar65/library.c
@@ -64,10 +64,11 @@
/* Name of the library file */
const char* LibName = 0;
+static const char* NewLibName = 0;
/* File descriptor for the library file */
-FILE* NewLib = 0;
static FILE* Lib = 0;
+static FILE* NewLib = 0;
/* The library header */
static LibHeader Header = {
@@ -246,10 +247,17 @@ void LibOpen (const char* Name, int MustExist, int NeedTemp)
}
if (NeedTemp) {
+
+ /* Create the temporary library name */
+ NewLibName = tempnam (NULL, NULL);
+ if (NewLibName == 0) {
+ Error ("Cannot create temporary library file name: %s", strerror (errno));
+ }
+
/* Create the temporary library */
- NewLib = tmpfile ();
+ NewLib = fopen (NewLibName, "w+b");
if (NewLib == 0) {
- Error ("Cannot create temporary file: %s", strerror (errno));
+ Error ("Cannot create temporary library file: %s", strerror (errno));
}
/* Write a dummy header to the temp file */
@@ -394,6 +402,9 @@ void LibClose (void)
if (NewLib && fclose (NewLib) != 0) {
Error ("Problem closing temporary library file: %s", strerror (errno));
}
+ if (NewLibName && remove (NewLibName) != 0) {
+ Error ("Problem deleting temporary library file: %s", strerror (errno));
+ }
}
diff --git a/src/ar65/library.h b/src/ar65/library.h
index abb8c475f..3453f1ea5 100644
--- a/src/ar65/library.h
+++ b/src/ar65/library.h
@@ -51,9 +51,6 @@
/* Name of the library file */
extern const char* LibName;
-/* File descriptor for the new library file */
-extern FILE* NewLib;
-
/*****************************************************************************/
diff --git a/src/ca65.vcxproj b/src/ca65.vcxproj
index 747b836cd..cb9727a81 100644
--- a/src/ca65.vcxproj
+++ b/src/ca65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
true
common
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
true
common
diff --git a/src/cc65.vcxproj b/src/cc65.vcxproj
index 888fa53b7..62d4bb416 100644
--- a/src/cc65.vcxproj
+++ b/src/cc65.vcxproj
@@ -46,7 +46,7 @@
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
Level3
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/cl65.vcxproj b/src/cl65.vcxproj
index ee348830d..8e11b90d3 100644
--- a/src/cl65.vcxproj
+++ b/src/cl65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/co65.vcxproj b/src/co65.vcxproj
index 7560cb866..ed63b91b0 100644
--- a/src/co65.vcxproj
+++ b/src/co65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/common.vcxproj b/src/common.vcxproj
index a386d0c06..938e4f032 100644
--- a/src/common.vcxproj
+++ b/src/common.vcxproj
@@ -143,7 +143,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_LIB;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_LIB;_DEBUG
true
@@ -161,7 +161,7 @@
true
- _CRT_SECURE_NO_WARNINGS;_LIB;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_LIB;NDEBUG
true
diff --git a/src/da65.vcxproj b/src/da65.vcxproj
index a71e46a65..8ca8935c1 100644
--- a/src/da65.vcxproj
+++ b/src/da65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/grc65.vcxproj b/src/grc65.vcxproj
index 29a8ca4b5..f41dafee3 100644
--- a/src/grc65.vcxproj
+++ b/src/grc65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/ld65.vcxproj b/src/ld65.vcxproj
index b837e1873..1674f0cd5 100644
--- a/src/ld65.vcxproj
+++ b/src/ld65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/od65.vcxproj b/src/od65.vcxproj
index abb2e7c8a..41639229a 100644
--- a/src/od65.vcxproj
+++ b/src/od65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/sim65.vcxproj b/src/sim65.vcxproj
index 7a65f9384..f8e9fd604 100644
--- a/src/sim65.vcxproj
+++ b/src/sim65.vcxproj
@@ -48,7 +48,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -63,7 +63,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
diff --git a/src/sp65.vcxproj b/src/sp65.vcxproj
index 1651ab007..477e80859 100644
--- a/src/sp65.vcxproj
+++ b/src/sp65.vcxproj
@@ -47,7 +47,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;_DEBUG
common
true
@@ -62,7 +62,7 @@
Level3
- _CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
+ _CRT_NONSTDC_NO_WARNINGS;_CRT_SECURE_NO_WARNINGS;_CONSOLE;NDEBUG
common
true
--
2.39.5