unique temp files for makedefs invocations (GitHub issue #391)
As reported in https://github.com/NetHack/NetHack/issues/391 if make was invoked with -j, makedefs instances could end up running in parallel and could trample on each other's grep.tmp tempory files. Default to using mkstemp(); allow a port runtime library implementation that lacks mkstemp() to define HAS_NO_MKSTEMP to revert to the old behaviour. Provide a work-alike mkstemp() implementation for windows Visual Studio build in mdlib.c so there is no requirement to define HAS_NO_MKSTEMP there. Fixes #391
This commit is contained in:
24
src/mdlib.c
24
src/mdlib.c
@@ -66,7 +66,14 @@ static char *FDECL(eos, (char *));
|
||||
#if 0
|
||||
static char *FDECL(mdlib_strsubst, (char *, const char *, const char *));
|
||||
#endif
|
||||
|
||||
#ifndef HAS_NO_MKSTEMP
|
||||
#ifdef _MSC_VER
|
||||
static int FDECL(mkstemp, (char *));
|
||||
#endif
|
||||
#endif
|
||||
#endif /* MAKEDEFS_C || FOR_RUNTIME */
|
||||
|
||||
#if !defined(MAKEDEFS_C) && defined(WIN32)
|
||||
extern int GUILaunched;
|
||||
#endif
|
||||
@@ -319,6 +326,23 @@ const char *build_date;
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
#ifndef HAS_NO_MKSTEMP
|
||||
#ifdef _MSC_VER
|
||||
int
|
||||
mkstemp(template)
|
||||
char *template;
|
||||
{
|
||||
int err;
|
||||
|
||||
err = _mktemp_s(template, strlen(template) + 1);
|
||||
if( err != 0 )
|
||||
return -1;
|
||||
return _open(template,
|
||||
_O_RDWR | _O_BINARY | _O_TEMPORARY | _O_CREAT,
|
||||
_S_IREAD | _S_IWRITE);
|
||||
}
|
||||
#endif /* _MSC_VER */
|
||||
#endif /* HAS_NO_MKSTEMP */
|
||||
#endif /* MAKEDEFS_C || FOR_RUNTIME */
|
||||
|
||||
static int
|
||||
|
||||
Reference in New Issue
Block a user