Commit 77feb693 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Add _wtmpnam_s implementation.

parent 9b6c93f6
......@@ -111,7 +111,7 @@
@ cdecl _wsopen_s(ptr wstr long long long) ucrtbase._wsopen_s
@ cdecl _wtempnam(wstr wstr) ucrtbase._wtempnam
@ cdecl _wtmpnam(ptr) ucrtbase._wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam_s(ptr long) ucrtbase._wtmpnam_s
@ cdecl clearerr(ptr) ucrtbase.clearerr
@ stub clearerr_s
@ cdecl fclose(ptr) ucrtbase.fclose
......
......@@ -1607,8 +1607,8 @@
@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
......@@ -1965,8 +1965,8 @@
@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
......@@ -1989,8 +1989,8 @@
@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
......@@ -1656,7 +1656,7 @@
@ cdecl _wstrtime_s(ptr long) msvcr120._wstrtime_s
@ cdecl _wtempnam(wstr wstr) msvcr120._wtempnam
@ cdecl _wtmpnam(ptr) msvcr120._wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam_s(ptr long) msvcr120._wtmpnam_s
@ cdecl _wtof(wstr) msvcr120._wtof
@ cdecl _wtof_l(wstr ptr) msvcr120._wtof_l
@ cdecl _wtoi(wstr) msvcr120._wtoi
......
......@@ -668,7 +668,7 @@
@ cdecl _wstrtime(ptr) MSVCRT__wstrtime
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtoi(wstr) MSVCRT__wtoi
@ cdecl -ret64 _wtoi64(wstr) MSVCRT__wtoi64
......
......@@ -664,7 +664,7 @@
@ cdecl _wstrtime(ptr) MSVCRT__wstrtime
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtoi(wstr) MSVCRT__wtoi
@ cdecl -ret64 _wtoi64(wstr) MSVCRT__wtoi64
......
......@@ -1290,8 +1290,8 @@
@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
......@@ -1262,8 +1262,8 @@
@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
......@@ -4852,15 +4852,68 @@ char * CDECL MSVCRT_tmpnam(char *s)
return tmpnam_helper(s, -1, &tmpnam_unique, MSVCRT_TMP_MAX) ? NULL : s;
}
static int wtmpnam_helper(MSVCRT_wchar_t *s, MSVCRT_size_t size, int *tmpnam_unique, int tmp_max)
{
MSVCRT_wchar_t tmpstr[8];
MSVCRT_wchar_t *p = s;
int digits;
if (!MSVCRT_CHECK_PMT(s != NULL)) return MSVCRT_EINVAL;
if (size < 3) {
if (size) *s = 0;
*MSVCRT__errno() = MSVCRT_ERANGE;
return MSVCRT_ERANGE;
}
*p++ = '\\';
*p++ = 's';
size -= 2;
digits = msvcrt_int_to_base32_w(GetCurrentProcessId(), tmpstr);
if (digits+1 > size) {
*s = 0;
*MSVCRT__errno() = MSVCRT_ERANGE;
return MSVCRT_ERANGE;
}
memcpy(p, tmpstr, digits*sizeof(tmpstr[0]));
p += digits;
*p++ = '.';
size -= digits+1;
while(1) {
while ((digits = *tmpnam_unique)+1 < tmp_max) {
if (InterlockedCompareExchange(tmpnam_unique, digits+1, digits) == digits)
break;
}
digits = msvcrt_int_to_base32_w(digits, tmpstr);
if (digits+1 > size) {
*s = 0;
*MSVCRT__errno() = MSVCRT_ERANGE;
return MSVCRT_ERANGE;
}
memcpy(p, tmpstr, digits*sizeof(tmpstr[0]));
p[digits] = 0;
if (GetFileAttributesW(s) == INVALID_FILE_ATTRIBUTES &&
GetLastError() == ERROR_FILE_NOT_FOUND)
break;
}
return 0;
}
/*********************************************************************
* _wtmpnam_s (MSVCRT.@)
*/
int CDECL MSVCRT__wtmpnam_s(MSVCRT_wchar_t *s, MSVCRT_size_t size)
{
return wtmpnam_helper(s, size, &tmpnam_s_unique, MSVCRT_TMP_MAX_S);
}
/*********************************************************************
* _wtmpnam (MSVCRT.@)
*/
MSVCRT_wchar_t * CDECL 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) {
thread_data_t *data = msvcrt_get_thread_data();
......@@ -4870,18 +4923,7 @@ MSVCRT_wchar_t * CDECL MSVCRT_wtmpnam(MSVCRT_wchar_t *s)
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++)
{
size = msvcrt_int_to_base32_w(tmpnam_unique++, tmpstr);
memcpy(p, tmpstr, size*sizeof(MSVCRT_wchar_t));
p[size] = '\0';
if (GetFileAttributesW(s) == INVALID_FILE_ATTRIBUTES &&
GetLastError() == ERROR_FILE_NOT_FOUND)
break;
}
return s;
return wtmpnam_helper(s, -1, &tmpnam_unique, MSVCRT_TMP_MAX) ? NULL : s;
}
/*********************************************************************
......
......@@ -1224,8 +1224,8 @@
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
# stub _wtempnam_dbg(wstr wstr long str long)
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
# stub _wtmpnam_s(ptr long)
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
......@@ -2131,8 +2131,8 @@
@ cdecl _wstrtime_s(ptr long)
@ cdecl _wsystem(wstr)
@ cdecl _wtempnam(wstr wstr) MSVCRT__wtempnam
@ cdecl _wtmpnam(ptr) MSVCRT_wtmpnam
@ stub _wtmpnam_s
@ cdecl _wtmpnam(ptr) MSVCRT__wtmpnam
@ cdecl _wtmpnam_s(ptr long) MSVCRT__wtmpnam_s
@ cdecl _wtof(wstr) MSVCRT__wtof
@ cdecl _wtof_l(wstr ptr) MSVCRT__wtof_l
@ cdecl _wtoi(wstr) MSVCRT__wtoi
......
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