wininet: Added new heap_strndupAtoW helper and use it in HttpAddRequestHeadersA.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-04-27 14:18:12 +02:00 committed by Alexandre Julliard
parent 41f69916c0
commit d282a64280
2 changed files with 24 additions and 9 deletions

View File

@ -1376,21 +1376,17 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest,
BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest,
LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier)
{
DWORD len;
LPWSTR hdr;
WCHAR *headers = NULL;
BOOL r;
TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_an(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier);
len = MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, NULL, 0 );
hdr = heap_alloc(len*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, hdr, len );
if( dwHeaderLength != ~0U )
dwHeaderLength = len;
if(lpszHeader)
headers = heap_strndupAtoW(lpszHeader, dwHeaderLength, &dwHeaderLength);
r = HttpAddRequestHeadersW( hHttpRequest, hdr, dwHeaderLength, dwModifier );
r = HttpAddRequestHeadersW(hHttpRequest, headers, dwHeaderLength, dwModifier);
heap_free( hdr );
heap_free(headers);
return r;
}

View File

@ -166,6 +166,25 @@ static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len)
return ret;
}
static inline WCHAR *heap_strndupAtoW(const char *str, int len_a, DWORD *len_w)
{
WCHAR *ret = NULL;
if(str) {
size_t len;
if(len_a < 0) len_a = strlen(str);
len = MultiByteToWideChar(CP_ACP, 0, str, len_a, NULL, 0);
ret = heap_alloc((len+1)*sizeof(WCHAR));
if(ret) {
MultiByteToWideChar(CP_ACP, 0, str, len_a, ret, len);
ret[len] = 0;
*len_w = len;
}
}
return ret;
}
static inline WCHAR *heap_strdupAtoW(const char *str)
{
LPWSTR ret = NULL;