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.
This commit is contained in:
Oliver Schmidt
2014-02-09 01:11:11 +01:00
parent 7b6a6d168c
commit bec75d9e62
14 changed files with 38 additions and 30 deletions

View File

@@ -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));
}
}

View File

@@ -51,9 +51,6 @@
/* Name of the library file */
extern const char* LibName;
/* File descriptor for the new library file */
extern FILE* NewLib;
/*****************************************************************************/