Changed tmpfileplus() to our needs

Removed exclusive flag, made it C++ friendly, replaced unlink() with remove()
This commit is contained in:
alexey.lysiuk 2017-11-04 13:12:13 +02:00
parent e60c6d35c3
commit e6c9ccf3a1
2 changed files with 11 additions and 3 deletions

View file

@ -200,13 +200,13 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, char **tmp
*/ */
#ifdef _WIN32 #ifdef _WIN32
/* MSVC flags */ /* MSVC flags */
oflag = _O_BINARY|_O_CREAT|_O_EXCL|_O_RDWR; oflag = _O_BINARY|_O_CREAT|_O_RDWR;
if (!keep) if (!keep)
oflag |= _O_TEMPORARY; oflag |= _O_TEMPORARY;
pmode = _S_IREAD | _S_IWRITE; pmode = _S_IREAD | _S_IWRITE;
#else #else
/* Standard POSIX flags */ /* Standard POSIX flags */
oflag = O_CREAT|O_EXCL|O_RDWR; oflag = O_CREAT|O_RDWR;
pmode = S_IRUSR|S_IWUSR; pmode = S_IRUSR|S_IWUSR;
#endif #endif
@ -239,7 +239,7 @@ static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, char **tmp
#ifndef _WIN32 #ifndef _WIN32
/* [Unix only] And make sure the file will be deleted once closed */ /* [Unix only] And make sure the file will be deleted once closed */
if (!keep) unlink(tmpname); if (!keep) remove(tmpname);
#endif #endif
} }

View file

@ -23,6 +23,10 @@
#include <stdio.h> #include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/** Create a unique temporary file. /** Create a unique temporary file.
@param dir (optional) directory to create file. If NULL use default TMP directory. @param dir (optional) directory to create file. If NULL use default TMP directory.
@param prefix (optional) prefix for file name. If NULL use "tmp.". @param prefix (optional) prefix for file name. If NULL use "tmp.".
@ -50,4 +54,8 @@ FILE *tmpfileplus_f(const char *dir, const char *prefix, char *pathnamebuf, size
#define TMPFILE_KEEP 1 #define TMPFILE_KEEP 1
#ifdef __cplusplus
}
#endif
#endif /* end TMPFILEPLUS_H_ */ #endif /* end TMPFILEPLUS_H_ */