makedefs temp files issue with mingw
The unlink call wasn't operating the same on a makedefs built on mingw, and dat/mdXXXX files were being left behind post-build. Provide an alternative way of doing the temporary files if MD_USE_TMPFILE_S is defined during the compile of makedefs.c
This commit is contained in:
@@ -103,6 +103,11 @@ extern void interject(int);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|
#define MD_USE_TMPFILE_S
|
||||||
|
#if !defined(__cplusplus)
|
||||||
|
extern errno_t tmpfile_s(FILE * restrict * restrict streamptr);
|
||||||
|
#endif
|
||||||
|
#
|
||||||
#ifdef strncasecmp
|
#ifdef strncasecmp
|
||||||
#undef strncasecmp
|
#undef strncasecmp
|
||||||
#endif
|
#endif
|
||||||
@@ -115,6 +120,7 @@ extern void interject(int);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
#define MD_USE_TMPFILE_S
|
||||||
#define HAS_STDINT
|
#define HAS_STDINT
|
||||||
#if (_MSC_VER > 1000)
|
#if (_MSC_VER > 1000)
|
||||||
/* Visual C 8 warning elimination */
|
/* Visual C 8 warning elimination */
|
||||||
|
|||||||
+27
-9
@@ -35,6 +35,10 @@
|
|||||||
#define SpinCursor(x)
|
#define SpinCursor(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MD_USE_TMPFILE_S
|
||||||
|
#include <errno.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define Fprintf (void) fprintf
|
#define Fprintf (void) fprintf
|
||||||
#define Fclose (void) fclose
|
#define Fclose (void) fclose
|
||||||
#define Unlink (void) unlink
|
#define Unlink (void) unlink
|
||||||
@@ -374,30 +378,44 @@ getfp(const char* template, const char* tag, const char* mode, int flg)
|
|||||||
{
|
{
|
||||||
char *name = name_file(template, tag);
|
char *name = name_file(template, tag);
|
||||||
FILE *rv = (FILE *) 0;
|
FILE *rv = (FILE *) 0;
|
||||||
#ifndef HAS_NO_MKSTEMP
|
|
||||||
boolean istemp = (flg & FLG_TEMPFILE) != 0;
|
boolean istemp = (flg & FLG_TEMPFILE) != 0;
|
||||||
|
#ifdef MD_USE_TMPFILE_S
|
||||||
|
errno_t err;
|
||||||
|
#endif
|
||||||
|
#if !defined(HAS_NO_MKSTEMP) && !defined(MD_USE_TMPFILE_S)
|
||||||
char tmpfbuf[MAXFNAMELEN];
|
char tmpfbuf[MAXFNAMELEN];
|
||||||
int tmpfd;
|
int tmpfd;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(HAS_NO_MKSTEMP) || defined(MD_USE_TMPFILE_S)
|
||||||
if (istemp) {
|
if (istemp) {
|
||||||
|
#ifdef MD_USE_TMPFILE_S
|
||||||
|
err = tmpfile_s(&rv);
|
||||||
|
#if defined(MSDOS) || defined(WIN32)
|
||||||
|
if (!err && (!strcmp(mode, WRTMODE) || !strcmp(mode, RDTMODE))) {
|
||||||
|
_setmode(fileno(rv), O_TEXT);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#else /* !MD_USE_TMPFILE_S */
|
||||||
(void) snprintf(tmpfbuf, sizeof tmpfbuf, DATA_TEMPLATE, "mdXXXXXX");
|
(void) snprintf(tmpfbuf, sizeof tmpfbuf, DATA_TEMPLATE, "mdXXXXXX");
|
||||||
tmpfd = mkstemp(tmpfbuf);
|
tmpfd = mkstemp(tmpfbuf);
|
||||||
if (tmpfd >= 0) {
|
if (tmpfd >= 0) {
|
||||||
rv = fdopen(tmpfd, WRTMODE); /* temp file is always read+write */
|
rv = fdopen(tmpfd, WRTMODE); /* temp file is always read+write */
|
||||||
Unlink(tmpfbuf);
|
Unlink(tmpfbuf);
|
||||||
}
|
}
|
||||||
}
|
#endif /* ?MD_USE_TMPFILE_S */
|
||||||
else
|
} else
|
||||||
#else
|
#endif /* !HAS_NO_MKSTEMP || MD_USE_TMPFILE_S */
|
||||||
flg; // unused
|
rv = fopen(name, mode);
|
||||||
#endif
|
|
||||||
rv = fopen(name, mode);
|
|
||||||
if (!rv) {
|
if (!rv) {
|
||||||
Fprintf(stderr, "Can't open '%s'.\n",
|
Fprintf(stderr, "Can't open '%s' (mode=%s).\n",
|
||||||
#ifndef HAS_NO_MKSTEMP
|
#ifndef HAS_NO_MKSTEMP
|
||||||
|
#if !defined(MD_USE_TMPFILE_S)
|
||||||
istemp ? tmpfbuf :
|
istemp ? tmpfbuf :
|
||||||
#endif
|
#endif
|
||||||
name);
|
#endif
|
||||||
|
name, mode);
|
||||||
makedefs_exit(EXIT_FAILURE);
|
makedefs_exit(EXIT_FAILURE);
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user