X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fextract.c;h=496d9c9870664ba050902139a942363197956605;hp=39da4bee378b1afedd0c8ab34f56c69ed45bc260;hb=011502c8756394066172b3164567a8b9835cc280;hpb=5ba1093ddc24f41f2f4179aeb8e2c8e86401af8c diff --git a/src/extract.c b/src/extract.c index 39da4bee..496d9c98 100644 --- a/src/extract.c +++ b/src/extract.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -315,27 +316,33 @@ static int create_temporary_file(struct filedes *fd_ret, tchar **name_ret) { tchar *name; - int open_flags; int raw_fd; +#ifdef __WIN32__ retry: - name = ttempnam(NULL, T("wimlib")); + name = _wtempnam(NULL, L"wimlib"); if (!name) { ERROR_WITH_ERRNO("Failed to create temporary filename"); return WIMLIB_ERR_NOMEM; } - - open_flags = O_WRONLY | O_CREAT | O_EXCL | O_BINARY; -#ifdef __WIN32__ - open_flags |= _O_SHORT_LIVED; -#endif - raw_fd = topen(name, open_flags, 0600); + raw_fd = _wopen(name, O_WRONLY | O_CREAT | O_EXCL | O_BINARY | + _O_SHORT_LIVED, 0600); + if (raw_fd < 0 && errno == EEXIST) { + FREE(name); + goto retry; + } +#else /* __WIN32__ */ + const char *tmpdir = getenv("TMPDIR"); + if (!tmpdir) + tmpdir = P_tmpdir; + name = MALLOC(strlen(tmpdir) + 1 + 6 + 6 + 1); + if (!name) + return WIMLIB_ERR_NOMEM; + sprintf(name, "%s/wimlibXXXXXX", tmpdir); + raw_fd = mkstemp(name); +#endif /* !__WIN32__ */ if (raw_fd < 0) { - if (errno == EEXIST) { - FREE(name); - goto retry; - } ERROR_WITH_ERRNO("Failed to create temporary file " "\"%"TS"\"", name); FREE(name);