63 lines
1.8 KiB
C
63 lines
1.8 KiB
C
|
/*
|
||
|
* Copyright 2015 Michael Müller
|
||
|
* Copyright 2015 Sebastian Lackner
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||
|
*/
|
||
|
|
||
|
static void *heap_alloc(size_t len) __WINE_ALLOC_SIZE(1);
|
||
|
static inline void *heap_alloc(size_t len)
|
||
|
{
|
||
|
return HeapAlloc(GetProcessHeap(), 0, len);
|
||
|
}
|
||
|
|
||
|
static inline BOOL heap_free(void *mem)
|
||
|
{
|
||
|
return HeapFree(GetProcessHeap(), 0, mem);
|
||
|
}
|
||
|
|
||
|
static inline char *strdupWtoA(const WCHAR *str)
|
||
|
{
|
||
|
char *ret = NULL;
|
||
|
DWORD len;
|
||
|
|
||
|
if (!str) return ret;
|
||
|
len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
|
||
|
if ((ret = heap_alloc(len)))
|
||
|
WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, NULL, NULL);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline WCHAR *strdupAtoW(const char *str)
|
||
|
{
|
||
|
WCHAR *ret = NULL;
|
||
|
DWORD len;
|
||
|
|
||
|
if (!str) return ret;
|
||
|
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
|
||
|
if ((ret = heap_alloc(len * sizeof(WCHAR))))
|
||
|
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline WCHAR *strdupW(const WCHAR *str)
|
||
|
{
|
||
|
WCHAR *ret;
|
||
|
if (!str) return NULL;
|
||
|
ret = heap_alloc((lstrlenW(str) + 1) * sizeof(WCHAR));
|
||
|
if (ret) lstrcpyW(ret, str);
|
||
|
return ret;
|
||
|
}
|