Commit 5437c72f authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

msvcrt: Implemented (_)wcserror_s.

parent 71200a98
......@@ -483,7 +483,7 @@
@ stub __vswprintf_l
@ extern __wargv msvcrt.__wargv
@ cdecl __wcserror(wstr) msvcrt.__wcserror
@ stub __wcserror_s
@ cdecl __wcserror_s(ptr long wstr) msvcrt.__wcserror_s
@ stub __wcsncnt
@ cdecl __wgetmainargs(ptr ptr ptr long ptr) msvcrt.__wgetmainargs
@ extern __winitenv msvcrt.__winitenv
......@@ -1285,7 +1285,7 @@
@ stub _wcscoll_l
@ cdecl _wcsdup(wstr) msvcrt._wcsdup
@ cdecl _wcserror(long) msvcrt._wcserror
@ stub _wcserror_s
@ cdecl _wcserror_s(ptr long long) msvcrt._wcserror_s
@ stub _wcsftime_l
@ cdecl _wcsicmp(wstr wstr) msvcrt._wcsicmp
@ stub _wcsicmp_l
......
......@@ -307,7 +307,7 @@
@ stub __vswprintf_l
@ extern __wargv msvcrt.__wargv
@ cdecl __wcserror(wstr) msvcrt.__wcserror
@ stub __wcserror_s
@ cdecl __wcserror_s(ptr long wstr) msvcrt.__wcserror_s
@ stub __wcsncnt
@ cdecl __wgetmainargs(ptr ptr ptr long ptr) msvcrt.__wgetmainargs
@ extern __winitenv msvcrt.__winitenv
......@@ -1138,7 +1138,7 @@
@ stub _wcscoll_l
@ cdecl _wcsdup(wstr) msvcrt._wcsdup
@ cdecl _wcserror(long) msvcrt._wcserror
@ stub _wcserror_s
@ cdecl _wcserror_s(ptr long long) msvcrt._wcserror_s
@ stub _wcsftime_l
@ cdecl _wcsicmp(wstr wstr) msvcrt._wcsicmp
@ stub _wcsicmp_l
......
......@@ -299,7 +299,7 @@
@ stub __vswprintf_l
@ extern __wargv msvcrt.__wargv
@ cdecl __wcserror(wstr) msvcrt.__wcserror
@ stub __wcserror_s
@ cdecl __wcserror_s(ptr long wstr) msvcrt.__wcserror_s
@ stub __wcsncnt
@ cdecl __wgetmainargs(ptr ptr ptr long ptr) msvcrt.__wgetmainargs
@ extern __winitenv msvcrt.__winitenv
......@@ -1125,7 +1125,7 @@
@ stub _wcscoll_l
@ cdecl _wcsdup(wstr) msvcrt._wcsdup
@ cdecl _wcserror(long) msvcrt._wcserror
@ stub _wcserror_s
@ cdecl _wcserror_s(ptr long long) msvcrt._wcserror_s
@ stub _wcsftime_l
@ cdecl _wcsicmp(wstr wstr) msvcrt._wcsicmp
@ stub _wcsicmp_l
......
......@@ -328,6 +328,21 @@ void CDECL MSVCRT_perror(const char* str)
}
/*********************************************************************
* _wcserror_s (MSVCRT.@)
*/
int CDECL _wcserror_s(MSVCRT_wchar_t* buffer, MSVCRT_size_t nc, int err)
{
if (!MSVCRT_CHECK_PMT(buffer != NULL) || !MSVCRT_CHECK_PMT(nc > 0))
{
_set_errno(MSVCRT_EINVAL);
return MSVCRT_EINVAL;
}
if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, buffer, nc);
return 0;
}
/*********************************************************************
* _wcserror (MSVCRT.@)
*/
MSVCRT_wchar_t* CDECL _wcserror(int err)
......@@ -336,38 +351,57 @@ MSVCRT_wchar_t* CDECL _wcserror(int err)
if (!data->wcserror_buffer)
if (!(data->wcserror_buffer = MSVCRT_malloc(256 * sizeof(MSVCRT_wchar_t)))) return NULL;
if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, data->wcserror_buffer, 256);
_wcserror_s(data->wcserror_buffer, 256, err);
return data->wcserror_buffer;
}
/**********************************************************************
* __wcserror (MSVCRT.@)
* __wcserror_s (MSVCRT.@)
*/
MSVCRT_wchar_t* CDECL __wcserror(const MSVCRT_wchar_t* str)
int CDECL __wcserror_s(MSVCRT_wchar_t* buffer, MSVCRT_size_t nc, const MSVCRT_wchar_t* str)
{
thread_data_t *data = msvcrt_get_thread_data();
int err;
static const WCHAR colonW[] = {':', ' ', '\0'};
static const WCHAR nlW[] = {'\n', '\0'};
size_t len;
if (!data->wcserror_buffer)
if (!(data->wcserror_buffer = MSVCRT_malloc(256 * sizeof(MSVCRT_wchar_t)))) return NULL;
err = data->thread_errno;
err = *MSVCRT__errno();
if (err < 0 || err > MSVCRT__sys_nerr) err = MSVCRT__sys_nerr;
len = MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, NULL, 0) + 1 /* \n */;
if (str && *str) len += lstrlenW(str) + 2 /* ': ' */;
if (len > nc)
{
MSVCRT_INVALID_PMT("buffer[nc] is too small");
_set_errno(MSVCRT_ERANGE);
return MSVCRT_ERANGE;
}
if (str && *str)
{
lstrcpyW(data->wcserror_buffer, str);
lstrcatW(data->wcserror_buffer, colonW);
lstrcpyW(buffer, str);
lstrcatW(buffer, colonW);
}
else data->wcserror_buffer[0] = '\0';
len = lstrlenW(data->wcserror_buffer);
MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, data->wcserror_buffer + len, 256 - len);
lstrcatW(data->wcserror_buffer, nlW);
else buffer[0] = '\0';
len = lstrlenW(buffer);
MultiByteToWideChar(CP_ACP, 0, MSVCRT__sys_errlist[err], -1, buffer + len, 256 - len);
lstrcatW(buffer, nlW);
return 0;
}
/**********************************************************************
* __wcserror (MSVCRT.@)
*/
MSVCRT_wchar_t* CDECL __wcserror(const MSVCRT_wchar_t* str)
{
thread_data_t *data = msvcrt_get_thread_data();
int err;
if (!data->wcserror_buffer)
if (!(data->wcserror_buffer = MSVCRT_malloc(256 * sizeof(MSVCRT_wchar_t)))) return NULL;
err = __wcserror_s(data->wcserror_buffer, 256, str);
if (err) FIXME("bad wcserror call (%d)\n", err);
return data->wcserror_buffer;
}
......
......@@ -264,7 +264,7 @@
@ extern __unguarded_readlc_active MSVCRT___unguarded_readlc_active
@ extern __wargv MSVCRT___wargv
@ cdecl __wcserror(wstr)
# stub __wcserror_s
@ cdecl __wcserror_s(ptr long wstr)
# stub __wcsncnt
@ cdecl __wgetmainargs(ptr ptr ptr long ptr)
@ extern __winitenv MSVCRT___winitenv
......@@ -1058,7 +1058,7 @@
@ cdecl _wcsdup(wstr)
# stub _wcsdup_dbg
@ cdecl _wcserror(long)
# stub _wcserror_s
@ cdecl _wcserror_s(ptr long long)
# stub _wcsftime_l
@ cdecl _wcsicmp(wstr wstr) ntdll._wcsicmp
# stub _wcsicmp_l
......
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