mirror of
https://git.proxmox.com/git/libgit2
synced 2025-07-17 08:38:46 +00:00
compat: Move mkstemp
to the POSIX compat layer
This commit is contained in:
parent
3ef7d06302
commit
f978b748bb
@ -55,18 +55,10 @@ int git_futils_mktmp(char *path_out, const char *filename)
|
||||
strcpy(path_out, filename);
|
||||
strcat(path_out, "_git2_XXXXXX");
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
/* FIXME: there may be race conditions when multi-threading
|
||||
* with the library */
|
||||
if (_mktemp_s(path_out, GIT_PATH_MAX) != 0)
|
||||
return git__throw(GIT_EOSERR, "Failed to make temporary file %s", path_out);
|
||||
if ((fd = p_mkstemp(path_out)) < 0)
|
||||
return git__throw(GIT_EOSERR, "Failed to create temporary file %s", path_out);
|
||||
|
||||
fd = p_creat(path_out, 0744);
|
||||
#else
|
||||
fd = mkstemp(path_out);
|
||||
#endif
|
||||
|
||||
return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create temporary file %s", path_out);
|
||||
return fd;
|
||||
}
|
||||
|
||||
int git_futils_creat_withpath(const char *path, int mode)
|
||||
|
@ -13,5 +13,6 @@
|
||||
#define p_fnmatch(p, s, f) fnmatch(p, s, f)
|
||||
#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
|
||||
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
|
||||
#define p_mkstemp(p) mkstemp(p)
|
||||
|
||||
#endif
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "posix.h"
|
||||
#include "path.h"
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
|
||||
int p_unlink(const char *path)
|
||||
{
|
||||
@ -230,3 +231,19 @@ int p_snprintf(char *buffer, size_t count, const char *format, ...)
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int p_mkstemp(char *tmp_path)
|
||||
{
|
||||
int r;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
r = _mktemp_s(tmp_path, GIT_PATH_MAX);
|
||||
#else
|
||||
r = _mktemp(tmp_path);
|
||||
#endif
|
||||
|
||||
if (r != 0)
|
||||
return GIT_EOSERR;
|
||||
|
||||
return p_creat(tmp_path, 0744);
|
||||
}
|
||||
|
@ -25,5 +25,6 @@ extern int p_hide_directory__w32(const char *path);
|
||||
extern char *p_realpath(const char *orig_path, char *buffer);
|
||||
extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
|
||||
extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4);
|
||||
extern int p_mkstemp(char *tmp_path);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user