Commit abb3db5c authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Improved tmpnam/wtmpnam implementation.

parent 12229aee
......@@ -108,8 +108,6 @@ static int MSVCRT_umask = 0;
/* INTERNAL: static data for tmpnam and _wtmpname functions */
static int tmpnam_unique;
static char MSVCRT_tmpname[MAX_PATH];
static MSVCRT_wchar_t MSVCRT_wtmpname[MAX_PATH];
static const unsigned int EXE = 'e' << 16 | 'x' << 8 | 'e';
static const unsigned int BAT = 'b' << 16 | 'a' << 8 | 't';
......@@ -3654,8 +3652,16 @@ char * CDECL MSVCRT_tmpnam(char *s)
char tmpstr[16];
char *p;
int count, size;
if (s == 0)
s = MSVCRT_tmpname;
if (!s) {
thread_data_t *data = msvcrt_get_thread_data();
if(!data->tmpnam_buffer)
data->tmpnam_buffer = MSVCRT_malloc(MAX_PATH);
s = data->tmpnam_buffer;
}
msvcrt_int_to_base32(GetCurrentProcessId(), tmpstr);
p = s + sprintf(s, "\\s%s.", tmpstr);
for (count = 0; count < MSVCRT_TMP_MAX; count++)
......@@ -3672,14 +3678,21 @@ char * CDECL MSVCRT_tmpnam(char *s)
/*********************************************************************
* _wtmpnam (MSVCRT.@)
*/
MSVCRT_wchar_t * MSVCRT_wtmpnam(MSVCRT_wchar_t *s)
MSVCRT_wchar_t * CDECL MSVCRT_wtmpnam(MSVCRT_wchar_t *s)
{
static const MSVCRT_wchar_t format[] = {'\\','s','%','s','.',0};
MSVCRT_wchar_t tmpstr[16];
MSVCRT_wchar_t *p;
int count, size;
if (s == 0)
s = MSVCRT_wtmpname;
if (!s) {
thread_data_t *data = msvcrt_get_thread_data();
if(!data->wtmpnam_buffer)
data->wtmpnam_buffer = MSVCRT_malloc(sizeof(MSVCRT_wchar_t[MAX_PATH]));
s = data->wtmpnam_buffer;
}
msvcrt_int_to_base32_w(GetCurrentProcessId(), tmpstr);
p = s + MSVCRT__snwprintf(s, MAX_PATH, format, tmpstr);
for (count = 0; count < MSVCRT_TMP_MAX; count++)
......
......@@ -169,7 +169,9 @@ struct __thread_data {
unsigned char *mbstok_next; /* next ptr for mbstok() */
char *strerror_buffer; /* buffer for strerror */
MSVCRT_wchar_t *wcserror_buffer; /* buffer for wcserror */
void *unk2[4];
char *tmpnam_buffer; /* buffer for tmpname() */
MSVCRT_wchar_t *wtmpnam_buffer; /* buffer for wtmpname() */
void *unk2[2];
char *asctime_buffer; /* buffer for asctime */
MSVCRT_wchar_t *wasctime_buffer; /* buffer for wasctime */
struct MSVCRT_tm *time_buffer; /* buffer for localtime/gmtime */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment