libwinpr-path: extend API with portability functions

This commit is contained in:
Marc-André Moreau 2012-10-16 17:18:12 -04:00
parent 1adcca8d29
commit d815369545
7 changed files with 1028 additions and 293 deletions

View File

@ -159,6 +159,95 @@ WINPR_API HRESULT PathCchRemoveFileSpecW(PWSTR pszPath, size_t cchPath);
#define PathCchRemoveFileSpec PathCchRemoveFileSpecA
#endif
/* Unix-style Paths */
WINPR_API HRESULT PathCchAddSlashA(PSTR pszPath, size_t cchPath);
WINPR_API HRESULT PathCchAddSlashW(PWSTR pszPath, size_t cchPath);
WINPR_API HRESULT PathCchAddSlashExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining);
WINPR_API HRESULT PathCchAddSlashExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd, size_t* pcchRemaining);
WINPR_API HRESULT UnixPathCchAddExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt);
WINPR_API HRESULT UnixPathCchAddExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt);
WINPR_API HRESULT UnixPathCchAppendA(PSTR pszPath, size_t cchPath, PCSTR pszMore);
WINPR_API HRESULT UnixPathCchAppendW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore);
WINPR_API HRESULT UnixPathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut);
WINPR_API HRESULT UnixPathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut);
#ifdef UNICODE
#define PathCchAddSlash PathCchAddSlashW
#define PathCchAddSlashEx PathCchAddSlashExW
#define UnixPathCchAddExtension UnixPathCchAddExtensionW
#define UnixPathCchAppend UnixPathCchAppendW
#define UnixPathAllocCombine UnixPathAllocCombineW
#else
#define PathCchAddSlash PathCchAddSlashA
#define PathCchAddSlashEx PathCchAddSlashExA
#define UnixPathCchAddExtension UnixPathCchAddExtensionA
#define UnixPathCchAppend UnixPathCchAppendA
#define UnixPathAllocCombine UnixPathAllocCombineA
#endif
/* Native-style Paths */
WINPR_API HRESULT PathCchAddSeparatorA(PSTR pszPath, size_t cchPath);
WINPR_API HRESULT PathCchAddSeparatorW(PWSTR pszPath, size_t cchPath);
WINPR_API HRESULT PathCchAddSeparatorExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining);
WINPR_API HRESULT PathCchAddSeparatorExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd, size_t* pcchRemaining);
WINPR_API HRESULT NativePathCchAddExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt);
WINPR_API HRESULT NativePathCchAddExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt);
WINPR_API HRESULT NativePathCchAppendA(PSTR pszPath, size_t cchPath, PCSTR pszMore);
WINPR_API HRESULT NativePathCchAppendW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore);
WINPR_API HRESULT NativePathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut);
WINPR_API HRESULT NativePathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut);
#ifdef UNICODE
#define PathCchAddSeparator PathCchAddSeparatorW
#define PathCchAddSeparatorEx PathCchAddSeparatorExW
#define NativePathCchAddExtension NativePathCchAddExtensionW
#define NativePathCchAppend NativePathCchAppendW
#define NativePathAllocCombine NativePathAllocCombineW
#else
#define PathCchAddSeparator PathCchAddSeparatorA
#define PathCchAddSeparatorEx PathCchAddSeparatorExA
#define NativePathCchAddExtension NativePathCchAddExtensionA
#define NativePathCchAppend NativePathCchAppendA
#define NativePathAllocCombine NativePathAllocCombineA
#endif
/* Path Portability Functions */
#define PATH_STYLE_WINDOWS 0x00000001
#define PATH_STYLE_UNIX 0x00000002
#define PATH_STYLE_NATIVE 0x00000003
#define PATH_SHARED_LIB_EXT_WITH_DOT 0x00000001
#define PATH_SHARED_LIB_EXT_APPLE_SO 0x00000002
#define PATH_SHARED_LIB_EXT_EXPLICIT 0x80000000
#define PATH_SHARED_LIB_EXT_EXPLICIT_DLL 0x80000001
#define PATH_SHARED_LIB_EXT_EXPLICIT_SO 0x80000002
#define PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB 0x80000003
WINPR_API HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags);
WINPR_API HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlags);
WINPR_API PCSTR PathGetSharedLibraryExtensionA(unsigned long dwFlags);
WINPR_API PCWSTR PathGetSharedLibraryExtensionW(unsigned long dwFlags);
#ifdef UNICODE
#define PathCchConvertStyle PathCchConvertStyleW
#define PathGetSharedLibraryExtension PathGetSharedLibraryExtensionW
#else
#define PathCchConvertStyle PathCchConvertStyleA
#define PathGetSharedLibraryExtension PathGetSharedLibraryExtensionA
#endif
#endif
#endif /* WINPR_PATH_H */

View File

@ -0,0 +1,143 @@
/*
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR '\\'
#define _PATH_SEPARATOR_STR "\\"
#define PATH_ALLOC_COMBINE PathAllocCombineA
*/
#if DEFINE_UNICODE
HRESULT PATH_ALLOC_COMBINE(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut)
{
#ifdef _WIN32
PWSTR pszPathOut;
BOOL backslashIn;
BOOL backslashMore;
int pszMoreLength;
int pszPathInLength;
int pszPathOutLength;
if (!pszPathIn)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszPathInLength = lstrlenW(pszPathIn);
pszMoreLength = lstrlenW(pszMore);
backslashIn = (pszPathIn[pszPathInLength - 1] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
backslashMore = (pszMore[0] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
if (backslashMore)
{
if ((pszPathIn[1] == ':') && (pszPathIn[2] == _PATH_SEPARATOR_CHR))
{
size_t sizeOfBuffer;
pszPathOutLength = 2 + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
swprintf_s(pszPathOut, sizeOfBuffer, L"%c:%s", pszPathIn[0], pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
}
else
{
size_t sizeOfBuffer;
pszPathOutLength = pszPathInLength + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
if (backslashIn)
swprintf_s(pszPathOut, sizeOfBuffer, L"%s%s", pszPathIn, pszMore);
else
swprintf_s(pszPathOut, sizeOfBuffer, L"%s" L _PATH_SEPARATOR_STR L"%s", pszPathIn, pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
#endif
return S_OK;
}
#else
HRESULT PATH_ALLOC_COMBINE(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut)
{
PSTR pszPathOut;
BOOL backslashIn;
BOOL backslashMore;
int pszMoreLength;
int pszPathInLength;
int pszPathOutLength;
if (!pszPathIn)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszPathInLength = lstrlenA(pszPathIn);
pszMoreLength = lstrlenA(pszMore);
backslashIn = (pszPathIn[pszPathInLength - 1] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
backslashMore = (pszMore[0] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
if (backslashMore)
{
if ((pszPathIn[1] == ':') && (pszPathIn[2] == _PATH_SEPARATOR_CHR))
{
size_t sizeOfBuffer;
pszPathOutLength = 2 + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
sprintf_s(pszPathOut, sizeOfBuffer, "%c:%s", pszPathIn[0], pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
}
else
{
size_t sizeOfBuffer;
pszPathOutLength = pszPathInLength + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
if (backslashIn)
sprintf_s(pszPathOut, sizeOfBuffer, "%s%s", pszPathIn, pszMore);
else
sprintf_s(pszPathOut, sizeOfBuffer, "%s" _PATH_SEPARATOR_STR "%s", pszPathIn, pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
return S_OK;
}
#endif
/*
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
*/

View File

@ -0,0 +1,100 @@
/*
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR '\\'
#define PATH_CCH_ADD_EXTENSION PathCchAddExtensionA
*/
#if DEFINE_UNICODE
HRESULT PATH_CCH_ADD_EXTENSION(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
{
#ifdef _WIN32
LPWSTR pDot;
BOOL bExtDot;
LPWSTR pBackslash;
size_t pszExtLength;
size_t pszPathLength;
if (!pszPath)
return S_FALSE;
if (!pszExt)
return S_FALSE;
pszExtLength = lstrlenW(pszExt);
pszPathLength = lstrlenW(pszPath);
bExtDot = (pszExt[0] == '.') ? TRUE : FALSE;
pDot = wcsrchr(pszPath, '.');
pBackslash = wcsrchr(pszPath, _PATH_SEPARATOR_CHR);
if (pDot && pBackslash)
{
if (pDot > pBackslash)
return S_FALSE;
}
if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
{
if (bExtDot)
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", pszExt);
else
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L".%s", pszExt);
return S_OK;
}
#endif
return S_FALSE;
}
#else
HRESULT PATH_CCH_ADD_EXTENSION(PSTR pszPath, size_t cchPath, PCSTR pszExt)
{
CHAR* pDot;
BOOL bExtDot;
CHAR* pBackslash;
size_t pszExtLength;
size_t pszPathLength;
if (!pszPath)
return S_FALSE;
if (!pszExt)
return S_FALSE;
pszExtLength = lstrlenA(pszExt);
pszPathLength = lstrlenA(pszPath);
bExtDot = (pszExt[0] == '.') ? TRUE : FALSE;
pDot = strrchr(pszPath, '.');
pBackslash = strrchr(pszPath, _PATH_SEPARATOR_CHR);
if (pDot && pBackslash)
{
if (pDot > pBackslash)
return S_FALSE;
}
if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
{
if (bExtDot)
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszExt);
else
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, ".%s", pszExt);
return S_OK;
}
return S_FALSE;
}
#endif
/*
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
*/

View File

@ -1,7 +1,7 @@
/*
#define DEFINE_UNICODE FALSE
#define PATH_SEPARATOR '\\'
#define _PATH_SEPARATOR_CHR '\\'
#define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashA
*/
@ -16,12 +16,12 @@ HRESULT PATH_CCH_ADD_SEPARATOR(PWSTR pszPath, size_t cchPath)
pszPathLength = lstrlenW(pszPath);
if (pszPath[pszPathLength - 1] == PATH_SEPARATOR)
if (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR)
return S_FALSE;
if (cchPath > (pszPathLength + 1))
{
pszPath[pszPathLength] = PATH_SEPARATOR;
pszPath[pszPathLength] = _PATH_SEPARATOR_CHR;
pszPath[pszPathLength + 1] = '\0';
return S_OK;
@ -41,12 +41,12 @@ HRESULT PATH_CCH_ADD_SEPARATOR(PSTR pszPath, size_t cchPath)
pszPathLength = lstrlenA(pszPath);
if (pszPath[pszPathLength - 1] == PATH_SEPARATOR)
if (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR)
return S_FALSE;
if (cchPath > (pszPathLength + 1))
{
pszPath[pszPathLength] = PATH_SEPARATOR;
pszPath[pszPathLength] = _PATH_SEPARATOR_CHR;
pszPath[pszPathLength + 1] = '\0';
return S_OK;
@ -59,7 +59,7 @@ HRESULT PATH_CCH_ADD_SEPARATOR(PSTR pszPath, size_t cchPath)
/*
#undef DEFINE_UNICODE
#undef PATH_SEPARATOR
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
*/

View File

@ -1,7 +1,7 @@
/*
#define DEFINE_UNICODE FALSE
#define PATH_SEPARATOR '\\'
#define _PATH_SEPARATOR_CHR '\\'
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExA
*/
@ -16,12 +16,12 @@ HRESULT PATH_CCH_ADD_SEPARATOR_EX(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd,
pszPathLength = lstrlenW(pszPath);
if (pszPath[pszPathLength - 1] == PATH_SEPARATOR)
if (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR)
return S_FALSE;
if (cchPath > (pszPathLength + 1))
{
pszPath[pszPathLength] = PATH_SEPARATOR;
pszPath[pszPathLength] = _PATH_SEPARATOR_CHR;
pszPath[pszPathLength + 1] = '\0';
return S_OK;
@ -41,12 +41,12 @@ HRESULT PATH_CCH_ADD_SEPARATOR_EX(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, s
pszPathLength = lstrlenA(pszPath);
if (pszPath[pszPathLength - 1] == PATH_SEPARATOR)
if (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR)
return S_FALSE;
if (cchPath > (pszPathLength + 1))
{
pszPath[pszPathLength] = PATH_SEPARATOR;
pszPath[pszPathLength] = _PATH_SEPARATOR_CHR;
pszPath[pszPathLength + 1] = '\0';
return S_OK;
@ -59,7 +59,7 @@ HRESULT PATH_CCH_ADD_SEPARATOR_EX(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, s
/*
#undef DEFINE_UNICODE
#undef PATH_SEPARATOR
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
*/

View File

@ -0,0 +1,117 @@
/*
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR '\\'
#define _PATH_SEPARATOR_STR "\\"
#define PATH_CCH_APPEND PathCchAppendA
*/
#if DEFINE_UNICODE
HRESULT PATH_CCH_APPEND(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
{
#ifdef _WIN32
BOOL pathBackslash;
BOOL moreBackslash;
size_t pszMoreLength;
size_t pszPathLength;
if (!pszPath)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszMoreLength = lstrlenW(pszMore);
pszPathLength = lstrlenW(pszPath);
pathBackslash = (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
moreBackslash = (pszMore[0] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
if (pathBackslash && moreBackslash)
{
if ((pszPathLength + pszMoreLength - 1) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", &pszMore[1]);
return S_OK;
}
}
else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
{
if ((pszPathLength + pszMoreLength) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", pszMore);
return S_OK;
}
}
else if (!pathBackslash && !moreBackslash)
{
if ((pszPathLength + pszMoreLength + 1) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L _PATH_SEPARATOR_STR L"%s", pszMore);
return S_OK;
}
}
#endif
return S_FALSE;
}
#else
HRESULT PATH_CCH_APPEND(PSTR pszPath, size_t cchPath, PCSTR pszMore)
{
BOOL pathBackslash;
BOOL moreBackslash;
size_t pszMoreLength;
size_t pszPathLength;
if (!pszPath)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszMoreLength = lstrlenA(pszMore);
pszPathLength = lstrlenA(pszPath);
pathBackslash = (pszPath[pszPathLength - 1] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
moreBackslash = (pszMore[0] == _PATH_SEPARATOR_CHR) ? TRUE : FALSE;
if (pathBackslash && moreBackslash)
{
if ((pszPathLength + pszMoreLength - 1) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);
return S_OK;
}
}
else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
{
if ((pszPathLength + pszMoreLength) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);
return S_OK;
}
}
else if (!pathBackslash && !moreBackslash)
{
if ((pszPathLength + pszMoreLength + 1) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, _PATH_SEPARATOR_STR "%s", pszMore);
return S_OK;
}
}
return S_FALSE;
}
#endif
/*
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
*/

View File

@ -27,22 +27,94 @@
#include <winpr/path.h>
#define PATH_SLASH_STR "/"
#define PATH_SLASH_CHR '/'
#define PATH_BACKSLASH_STR "\\"
#define PATH_BACKSLASH_CHR '\\'
#ifdef _WIN32
#define PATH_SEPARATOR_STR PATH_BACKSLASH_STR
#define PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#else
#define PATH_SEPARATOR_STR PATH_SLASH_STR
#define PATH_SEPARATOR_CHR PATH_SLASH_CHR
#endif
#define SHARED_LIBRARY_EXT_DLL "dll"
#define SHARED_LIBRARY_EXT_SO "so"
#define SHARED_LIBRARY_EXT_DYLIB "dylib"
#ifdef _WIN32
#define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_DLL
#elif __APPLE__
#define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_DYLIB
#else
#define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_SO
#endif
/*
* PathCchAddBackslash
*/
/* Windows-style Paths */
#define DEFINE_UNICODE FALSE
#define PATH_SEPARATOR '\\'
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashA
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef PATH_SEPARATOR
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
#define DEFINE_UNICODE TRUE
#define PATH_SEPARATOR '\\'
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashW
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef PATH_SEPARATOR
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
/* Unix-style Paths */
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddSlashA
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddSlashW
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
/* Native-style Paths */
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddSeparatorA
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddSeparatorW
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
/*
* PathCchRemoveBackslash
*/
HRESULT PathCchRemoveBackslashA(PSTR pszPath, size_t cchPath)
{
return 0;
@ -53,20 +125,62 @@ HRESULT PathCchRemoveBackslashW(PWSTR pszPath, size_t cchPath)
return 0;
}
/*
* PathCchAddBackslashEx
*/
/* Windows-style Paths */
#define DEFINE_UNICODE FALSE
#define PATH_SEPARATOR '\\'
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExA
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef PATH_SEPARATOR
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
#define DEFINE_UNICODE TRUE
#define PATH_SEPARATOR '\\'
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExW
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef PATH_SEPARATOR
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
/* Unix-style Paths */
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSlashExA
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSlashExW
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
/* Native-style Paths */
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSeparatorExA
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddSeparatorExW
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR_EX
HRESULT PathCchRemoveBackslashExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd, size_t* pcchRemaining)
@ -79,182 +193,93 @@ HRESULT PathCchRemoveBackslashExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd,
return 0;
}
HRESULT PathCchAddExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt)
{
CHAR* pDot;
BOOL bExtDot;
CHAR* pBackslash;
size_t pszExtLength;
size_t pszPathLength;
/*
* PathCchAddExtension
*/
if (!pszPath)
return S_FALSE;
/* Windows-style Paths */
if (!pszExt)
return S_FALSE;
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_EXTENSION PathCchAddExtensionA
#include "include/PathCchAddExtension.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
pszExtLength = lstrlenA(pszExt);
pszPathLength = lstrlenA(pszPath);
bExtDot = (pszExt[0] == '.') ? TRUE : FALSE;
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_EXTENSION PathCchAddExtensionW
#include "include/PathCchAddExtension.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
pDot = strrchr(pszPath, '.');
pBackslash = strrchr(pszPath, '\\');
/* Unix-style Paths */
if (pDot && pBackslash)
{
if (pDot > pBackslash)
return S_FALSE;
}
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_CCH_ADD_EXTENSION UnixPathCchAddExtensionA
#include "include/PathCchAddExtension.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
{
if (bExtDot)
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszExt);
else
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, ".%s", pszExt);
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_CCH_ADD_EXTENSION UnixPathCchAddExtensionW
#include "include/PathCchAddExtension.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
return S_OK;
}
/* Native-style Paths */
return S_FALSE;
}
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define PATH_CCH_ADD_EXTENSION NativePathCchAddExtensionA
#include "include/PathCchAddExtension.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
HRESULT PathCchAddExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
{
#ifdef _WIN32
LPTCH pDot;
BOOL bExtDot;
LPTCH pBackslash;
size_t pszExtLength;
size_t pszPathLength;
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define PATH_CCH_ADD_EXTENSION NativePathCchAddExtensionW
#include "include/PathCchAddExtension.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_EXTENSION
if (!pszPath)
return S_FALSE;
/*
* PathCchAppend
*/
if (!pszExt)
return S_FALSE;
/* Windows-style Paths */
pszExtLength = lstrlenW(pszExt);
pszPathLength = lstrlenW(pszPath);
bExtDot = (pszExt[0] == '.') ? TRUE : FALSE;
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define _PATH_SEPARATOR_STR PATH_BACKSLASH_STR
#define PATH_CCH_APPEND PathCchAppendA
#include "include/PathCchAppend.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
pDot = wcsrchr(pszPath, '.');
pBackslash = wcsrchr(pszPath, '\\');
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define _PATH_SEPARATOR_STR PATH_BACKSLASH_STR
#define PATH_CCH_APPEND PathCchAppendW
#include "include/PathCchAppend.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
if (pDot && pBackslash)
{
if (pDot > pBackslash)
return S_FALSE;
}
if (cchPath > pszPathLength + pszExtLength + ((bExtDot) ? 0 : 1))
{
if (bExtDot)
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", pszExt);
else
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L".%s", pszExt);
return S_OK;
}
#endif
return S_FALSE;
}
HRESULT PathCchAppendA(PSTR pszPath, size_t cchPath, PCSTR pszMore)
{
BOOL pathBackslash;
BOOL moreBackslash;
size_t pszMoreLength;
size_t pszPathLength;
if (!pszPath)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszMoreLength = lstrlenA(pszMore);
pszPathLength = lstrlenA(pszPath);
pathBackslash = (pszPath[pszPathLength - 1] == '\\') ? TRUE : FALSE;
moreBackslash = (pszMore[0] == '\\') ? TRUE : FALSE;
if (pathBackslash && moreBackslash)
{
if ((pszPathLength + pszMoreLength - 1) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", &pszMore[1]);
return S_OK;
}
}
else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
{
if ((pszPathLength + pszMoreLength) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "%s", pszMore);
return S_OK;
}
}
else if (!pathBackslash && !moreBackslash)
{
if ((pszPathLength + pszMoreLength + 1) < cchPath)
{
sprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, "\\%s", pszMore);
return S_OK;
}
}
return S_FALSE;
}
HRESULT PathCchAppendW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore)
{
#ifdef _WIN32
BOOL pathBackslash;
BOOL moreBackslash;
size_t pszMoreLength;
size_t pszPathLength;
if (!pszPath)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszMoreLength = lstrlenW(pszMore);
pszPathLength = lstrlenW(pszPath);
pathBackslash = (pszPath[pszPathLength - 1] == '\\') ? TRUE : FALSE;
moreBackslash = (pszMore[0] == '\\') ? TRUE : FALSE;
if (pathBackslash && moreBackslash)
{
if ((pszPathLength + pszMoreLength - 1) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", &pszMore[1]);
return S_OK;
}
}
else if ((pathBackslash && !moreBackslash) || (!pathBackslash && moreBackslash))
{
if ((pszPathLength + pszMoreLength) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"%s", pszMore);
return S_OK;
}
}
else if (!pathBackslash && !moreBackslash)
{
if ((pszPathLength + pszMoreLength + 1) < cchPath)
{
swprintf_s(&pszPath[pszPathLength], cchPath - pszPathLength, L"\\%s", pszMore);
return S_OK;
}
}
#endif
return S_FALSE;
}
/*
* PathCchAppendEx
*/
HRESULT PathCchAppendExA(PSTR pszPath, size_t cchPath, PCSTR pszMore, unsigned long dwFlags)
{
@ -266,6 +291,10 @@ HRESULT PathCchAppendExW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore, unsigned
return 0;
}
/*
* PathCchCanonicalize
*/
HRESULT PathCchCanonicalizeA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn)
{
return 0;
@ -276,6 +305,10 @@ HRESULT PathCchCanonicalizeW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPath
return 0;
}
/*
* PathCchCanonicalizeEx
*/
HRESULT PathCchCanonicalizeExA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, unsigned long dwFlags)
{
return 0;
@ -286,6 +319,10 @@ HRESULT PathCchCanonicalizeExW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPa
return 0;
}
/*
* PathAllocCanonicalize
*/
HRESULT PathAllocCanonicalizeA(PCSTR pszPathIn, unsigned long dwFlags, PSTR* ppszPathOut)
{
return 0;
@ -296,6 +333,10 @@ HRESULT PathAllocCanonicalizeW(PCWSTR pszPathIn, unsigned long dwFlags, PWSTR* p
return 0;
}
/*
* PathCchCombine
*/
HRESULT PathCchCombineA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore)
{
return 0;
@ -306,6 +347,10 @@ HRESULT PathCchCombineW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn, P
return 0;
}
/*
* PathCchCombineEx
*/
HRESULT PathCchCombineExA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags)
{
return 0;
@ -316,127 +361,79 @@ HRESULT PathCchCombineExW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn,
return 0;
}
HRESULT PathAllocCombineA(PCSTR pszPathIn, PCSTR pszMore, unsigned long dwFlags, PSTR* ppszPathOut)
{
PSTR pszPathOut;
BOOL backslashIn;
BOOL backslashMore;
int pszMoreLength;
int pszPathInLength;
int pszPathOutLength;
/*
* PathAllocCombine
*/
if (!pszPathIn)
return S_FALSE;
/* Windows-style Paths */
if (!pszMore)
return S_FALSE;
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define _PATH_SEPARATOR_STR PATH_BACKSLASH_STR
#define PATH_ALLOC_COMBINE PathAllocCombineA
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
pszPathInLength = lstrlenA(pszPathIn);
pszMoreLength = lstrlenA(pszMore);
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define _PATH_SEPARATOR_STR PATH_BACKSLASH_STR
#define PATH_ALLOC_COMBINE PathAllocCombineW
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
backslashIn = (pszPathIn[pszPathInLength - 1] == '\\') ? TRUE : FALSE;
backslashMore = (pszMore[0] == '\\') ? TRUE : FALSE;
/* Unix-style Paths */
if (backslashMore)
{
if ((pszPathIn[1] == ':') && (pszPathIn[2] == '\\'))
{
size_t sizeOfBuffer;
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define _PATH_SEPARATOR_STR PATH_SLASH_STR
#define PATH_ALLOC_COMBINE UnixPathAllocCombineA
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
pszPathOutLength = 2 + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define _PATH_SEPARATOR_STR PATH_SLASH_STR
#define PATH_ALLOC_COMBINE UnixPathAllocCombineW
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
pszPathOut = (PSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
sprintf_s(pszPathOut, sizeOfBuffer, "%c:%s", pszPathIn[0], pszMore);
/* Native-style Paths */
*ppszPathOut = pszPathOut;
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define _PATH_SEPARATOR_STR PATH_SEPARATOR_STR
#define PATH_ALLOC_COMBINE NativePathAllocCombineA
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
return S_OK;
}
}
else
{
size_t sizeOfBuffer;
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define _PATH_SEPARATOR_STR PATH_SEPARATOR_STR
#define PATH_ALLOC_COMBINE NativePathAllocCombineW
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
pszPathOutLength = pszPathInLength + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
if (backslashIn)
sprintf_s(pszPathOut, sizeOfBuffer, "%s%s", pszPathIn, pszMore);
else
sprintf_s(pszPathOut, sizeOfBuffer, "%s\\%s", pszPathIn, pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
return S_OK;
}
HRESULT PathAllocCombineW(PCWSTR pszPathIn, PCWSTR pszMore, unsigned long dwFlags, PWSTR* ppszPathOut)
{
#ifdef _WIN32
PWSTR pszPathOut;
BOOL backslashIn;
BOOL backslashMore;
int pszMoreLength;
int pszPathInLength;
int pszPathOutLength;
if (!pszPathIn)
return S_FALSE;
if (!pszMore)
return S_FALSE;
pszPathInLength = lstrlenW(pszPathIn);
pszMoreLength = lstrlenW(pszMore);
backslashIn = (pszPathIn[pszPathInLength - 1] == '\\') ? TRUE : FALSE;
backslashMore = (pszMore[0] == '\\') ? TRUE : FALSE;
if (backslashMore)
{
if ((pszPathIn[1] == ':') && (pszPathIn[2] == '\\'))
{
size_t sizeOfBuffer;
pszPathOutLength = 2 + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
swprintf_s(pszPathOut, sizeOfBuffer, L"%c:%s", pszPathIn[0], pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
}
else
{
size_t sizeOfBuffer;
pszPathOutLength = pszPathInLength + pszMoreLength;
sizeOfBuffer = (pszPathOutLength + 1) * 2;
pszPathOut = (PWSTR) HeapAlloc(GetProcessHeap(), 0, sizeOfBuffer * 2);
if (backslashIn)
swprintf_s(pszPathOut, sizeOfBuffer, L"%s%s", pszPathIn, pszMore);
else
swprintf_s(pszPathOut, sizeOfBuffer, L"%s\\%s", pszPathIn, pszMore);
*ppszPathOut = pszPathOut;
return S_OK;
}
#endif
return S_OK;
}
/**
* PathCchFindExtension
*/
HRESULT PathCchFindExtensionA(PCSTR pszPath, size_t cchPath, PCSTR* ppszExt)
{
@ -448,6 +445,10 @@ HRESULT PathCchFindExtensionW(PCWSTR pszPath, size_t cchPath, PCWSTR* ppszExt)
return 0;
}
/**
* PathCchRenameExtension
*/
HRESULT PathCchRenameExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt)
{
return 0;
@ -458,6 +459,10 @@ HRESULT PathCchRenameExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
return 0;
}
/**
* PathCchRemoveExtension
*/
HRESULT PathCchRemoveExtensionA(PSTR pszPath, size_t cchPath)
{
return 0;
@ -468,6 +473,10 @@ HRESULT PathCchRemoveExtensionW(PWSTR pszPath, size_t cchPath)
return 0;
}
/**
* PathCchIsRoot
*/
BOOL PathCchIsRootA(PCSTR pszPath)
{
return 0;
@ -478,6 +487,10 @@ BOOL PathCchIsRootW(PCWSTR pszPath)
return 0;
}
/**
* PathIsUNCEx
*/
BOOL PathIsUNCExA(PCSTR pszPath, PCSTR* ppszServer)
{
if (!pszPath)
@ -506,6 +519,10 @@ BOOL PathIsUNCExW(PCWSTR pszPath, PCWSTR* ppszServer)
return FALSE;
}
/**
* PathCchSkipRoot
*/
HRESULT PathCchSkipRootA(PCSTR pszPath, PCSTR* ppszRootEnd)
{
return 0;
@ -516,6 +533,10 @@ HRESULT PathCchSkipRootW(PCWSTR pszPath, PCWSTR* ppszRootEnd)
return 0;
}
/**
* PathCchStripToRoot
*/
HRESULT PathCchStripToRootA(PSTR pszPath, size_t cchPath)
{
return 0;
@ -526,6 +547,10 @@ HRESULT PathCchStripToRootW(PWSTR pszPath, size_t cchPath)
return 0;
}
/**
* PathCchStripPrefix
*/
HRESULT PathCchStripPrefixA(PSTR pszPath, size_t cchPath)
{
BOOL hasPrefix;
@ -588,6 +613,10 @@ HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath)
return S_FALSE;
}
/**
* PathCchRemoveFileSpec
*/
HRESULT PathCchRemoveFileSpecA(PSTR pszPath, size_t cchPath)
{
return 0;
@ -598,3 +627,260 @@ HRESULT PathCchRemoveFileSpecW(PWSTR pszPath, size_t cchPath)
return 0;
}
/*
* Path Portability Functions
*/
/**
* PathCchConvertStyle
*/
HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags)
{
int index;
if (dwFlags & PATH_STYLE_WINDOWS)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_SLASH_CHR)
pszPath[index] = PATH_BACKSLASH_CHR;
}
}
else if (dwFlags & PATH_STYLE_UNIX)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_BACKSLASH_CHR)
pszPath[index] = PATH_SLASH_CHR;
}
}
else if (dwFlags & PATH_STYLE_NATIVE)
{
if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR)
{
/* Unix-style to Windows-style */
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_SLASH_CHR)
pszPath[index] = PATH_BACKSLASH_CHR;
}
}
else if (PATH_SEPARATOR_CHR == PATH_SLASH_CHR)
{
/* Windows-style to Unix-style */
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_BACKSLASH_CHR)
pszPath[index] = PATH_SLASH_CHR;
}
}
else
{
/* Unexpected error */
return S_FALSE;
}
}
else
{
/* Gangnam style? */
return S_FALSE;
}
return S_OK;
}
HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlags)
{
int index;
if (dwFlags & PATH_STYLE_WINDOWS)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_SLASH_CHR)
pszPath[index] = PATH_BACKSLASH_CHR;
}
}
else if (dwFlags & PATH_STYLE_UNIX)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_BACKSLASH_CHR)
pszPath[index] = PATH_SLASH_CHR;
}
}
else if (dwFlags & PATH_STYLE_NATIVE)
{
if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR)
{
/* Unix-style to Windows-style */
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_SLASH_CHR)
pszPath[index] = PATH_BACKSLASH_CHR;
}
}
else if (PATH_SEPARATOR_CHR == PATH_SLASH_CHR)
{
/* Windows-style to Unix-style */
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_BACKSLASH_CHR)
pszPath[index] = PATH_SLASH_CHR;
}
}
else
{
/* Unexpected error */
return S_FALSE;
}
}
else
{
/* Gangnam style? */
return S_FALSE;
}
return S_OK;
}
/**
* PathGetSharedLibraryExtension
*/
static const CHAR SharedLibraryExtensionDllA[] = "dll";
static const CHAR SharedLibraryExtensionSoA[] = "so";
static const CHAR SharedLibraryExtensionDylibA[] = "dylib";
static const WCHAR SharedLibraryExtensionDllW[] = { 'd','l','l' };
static const WCHAR SharedLibraryExtensionSoW[] = { 's','o' };
static const WCHAR SharedLibraryExtensionDylibW[] = { 'd','y','l','i','b' };
static const CHAR SharedLibraryExtensionDotDllA[] = ".dll";
static const CHAR SharedLibraryExtensionDotSoA[] = ".so";
static const CHAR SharedLibraryExtensionDotDylibA[] = ".dylib";
static const WCHAR SharedLibraryExtensionDotDllW[] = { '.','d','l','l' };
static const WCHAR SharedLibraryExtensionDotSoW[] = { '.','s','o' };
static const WCHAR SharedLibraryExtensionDotDylibW[] = { '.','d','y','l','i','b' };
PCSTR PathGetSharedLibraryExtensionA(unsigned long dwFlags)
{
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT)
{
if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
{
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
return SharedLibraryExtensionDotDllA;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
return SharedLibraryExtensionDotSoA;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
return SharedLibraryExtensionDotDylibA;
}
else
{
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
return SharedLibraryExtensionDllA;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
return SharedLibraryExtensionSoA;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
return SharedLibraryExtensionDylibA;
}
}
if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
{
#ifdef _WIN32
return SharedLibraryExtensionDotDllA;
#elif __APPLE__
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionDotSoA;
else
return SharedLibraryExtensionDotDylibA;
#else
return SharedLibraryExtensionDotSoA;
#endif
}
else
{
#ifdef _WIN32
return SharedLibraryExtensionDllA;
#elif __APPLE__
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionSoA;
else
return SharedLibraryExtensionDylibA;
#else
return SharedLibraryExtensionSoA;
#endif
}
return NULL;
}
PCWSTR PathGetSharedLibraryExtensionW(unsigned long dwFlags)
{
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT)
{
if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
{
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
return SharedLibraryExtensionDotDllW;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
return SharedLibraryExtensionDotSoW;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
return SharedLibraryExtensionDotDylibW;
}
else
{
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DLL)
return SharedLibraryExtensionDllW;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_SO)
return SharedLibraryExtensionSoW;
if (dwFlags & PATH_SHARED_LIB_EXT_EXPLICIT_DYLIB)
return SharedLibraryExtensionDylibW;
}
}
if (dwFlags & PATH_SHARED_LIB_EXT_WITH_DOT)
{
#ifdef _WIN32
return SharedLibraryExtensionDotDllW;
#elif __APPLE__
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionDotSoW;
else
return SharedLibraryExtensionDotDylibW;
#else
return SharedLibraryExtensionDotSoW;
#endif
}
else
{
#ifdef _WIN32
return SharedLibraryExtensionDllW;
#elif __APPLE__
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionSoW;
else
return SharedLibraryExtensionDylibW;
#else
return SharedLibraryExtensionSoW;
#endif
}
return NULL;
}