87 lines
2.5 KiB
C
87 lines
2.5 KiB
C
|
/*
|
||
|
* WLDAP32 - LDAP support for Wine
|
||
|
*
|
||
|
* Copyright 2005 Hans Leidekker
|
||
|
*
|
||
|
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||
|
*/
|
||
|
|
||
|
/* A set of helper functions to convert LDAP data structures
|
||
|
* to and from ansi (A), wide character (W) and utf8 (U) encodings.
|
||
|
*/
|
||
|
|
||
|
static inline LPWSTR strAtoW( LPCSTR str )
|
||
|
{
|
||
|
LPWSTR ret = NULL;
|
||
|
if (str)
|
||
|
{
|
||
|
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
|
||
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
||
|
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline LPSTR strWtoA( LPCWSTR str )
|
||
|
{
|
||
|
LPSTR ret = NULL;
|
||
|
if (str)
|
||
|
{
|
||
|
DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
|
||
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
|
||
|
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline char *strWtoU( LPCWSTR str )
|
||
|
{
|
||
|
LPSTR ret = NULL;
|
||
|
if (str)
|
||
|
{
|
||
|
DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
|
||
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
|
||
|
WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline LPWSTR strUtoW( char *str )
|
||
|
{
|
||
|
LPWSTR ret = NULL;
|
||
|
if (str)
|
||
|
{
|
||
|
DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
|
||
|
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
|
||
|
MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
static inline void strfreeA( LPSTR str )
|
||
|
{
|
||
|
HeapFree( GetProcessHeap(), 0, str );
|
||
|
}
|
||
|
|
||
|
static inline void strfreeW( LPWSTR str )
|
||
|
{
|
||
|
HeapFree( GetProcessHeap(), 0, str );
|
||
|
}
|
||
|
|
||
|
static inline void strfreeU( char *str )
|
||
|
{
|
||
|
HeapFree( GetProcessHeap(), 0, str );
|
||
|
}
|