FreeRDP/winpr/libwinpr/path/path.c

1067 lines
24 KiB
C
Raw Normal View History

2012-09-23 06:02:55 +04:00
/**
* WinPR: Windows Portable Runtime
* Path Functions
*
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2012-10-05 07:19:05 +04:00
#include <winpr/crt.h>
2012-10-02 02:34:46 +04:00
#include <winpr/heap.h>
2012-10-05 07:19:05 +04:00
#include <winpr/tchar.h>
2012-10-02 02:34:46 +04:00
2012-09-23 06:02:55 +04:00
#include <winpr/path.h>
2019-11-06 17:24:51 +03:00
#define PATH_SLASH_CHR '/'
#define PATH_SLASH_STR "/"
2019-11-06 17:24:51 +03:00
#define PATH_BACKSLASH_CHR '\\'
#define PATH_BACKSLASH_STR "\\"
2012-10-17 15:48:24 +04:00
#ifdef _WIN32
2019-11-06 17:24:51 +03:00
#define PATH_SLASH_STR_W L"/"
#define PATH_BACKSLASH_STR_W L"\\"
2012-10-17 15:48:24 +04:00
#else
2019-11-06 17:24:51 +03:00
#define PATH_SLASH_STR_W "/"
#define PATH_BACKSLASH_STR_W "\\"
2012-10-17 15:48:24 +04:00
#endif
#ifdef _WIN32
2019-11-06 17:24:51 +03:00
#define PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_SEPARATOR_STR PATH_BACKSLASH_STR
#define PATH_SEPARATOR_STR_W PATH_BACKSLASH_STR_W
#else
2019-11-06 17:24:51 +03:00
#define PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define PATH_SEPARATOR_STR PATH_SLASH_STR
#define PATH_SEPARATOR_STR_W PATH_SLASH_STR_W
#endif
2019-11-06 17:24:51 +03:00
#define SHARED_LIBRARY_EXT_DLL "dll"
#define SHARED_LIBRARY_EXT_SO "so"
#define SHARED_LIBRARY_EXT_DYLIB "dylib"
#ifdef _WIN32
2019-11-06 17:24:51 +03:00
#define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_DLL
#elif defined(__APPLE__)
2019-11-06 17:24:51 +03:00
#define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_DYLIB
#else
2019-11-06 17:24:51 +03:00
#define SHARED_LIBRARY_EXT SHARED_LIBRARY_EXT_SO
#endif
#include "../log.h"
#define TAG WINPR_TAG("path")
/*
* PathCchAddBackslash
*/
/* Windows-style Paths */
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashA
2012-10-16 20:41:16 +04:00
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
2012-10-16 20:41:16 +04:00
#undef PATH_CCH_ADD_SEPARATOR
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR PathCchAddBackslashW
2012-10-16 20:41:16 +04:00
#include "include/PathCchAddSeparator.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef PATH_CCH_ADD_SEPARATOR
/* Unix-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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 */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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
2012-10-16 20:41:16 +04:00
#undef PATH_CCH_ADD_SEPARATOR
2012-09-23 06:02:55 +04:00
/*
* PathCchRemoveBackslash
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchRemoveBackslashA(PSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchRemoveBackslashW(PWSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathCchAddBackslashEx
*/
/* Windows-style Paths */
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExA
2012-10-16 20:41:16 +04:00
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
2012-10-16 20:41:16 +04:00
#undef PATH_CCH_ADD_SEPARATOR_EX
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define PATH_CCH_ADD_SEPARATOR_EX PathCchAddBackslashExW
2012-10-16 20:41:16 +04:00
#include "include/PathCchAddSeparatorEx.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
2012-10-16 20:41:16 +04:00
#undef PATH_CCH_ADD_SEPARATOR_EX
2012-09-23 06:02:55 +04:00
/* Unix-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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 */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
HRESULT PathCchRemoveBackslashExA(PSTR pszPath, size_t cchPath, PSTR* ppszEnd,
size_t* pcchRemaining)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
2019-11-06 17:24:51 +03:00
HRESULT PathCchRemoveBackslashExW(PWSTR pszPath, size_t cchPath, PWSTR* ppszEnd,
size_t* pcchRemaining)
2012-09-23 06:02:55 +04:00
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathCchAddExtension
*/
/* Windows-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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
/* Unix-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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
2012-09-23 06:02:55 +04:00
/* Native-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#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
/*
* PathCchAppend
*/
/* Windows-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define _PATH_SEPARATOR_STR PATH_BACKSLASH_STR_W
#define PATH_CCH_APPEND PathCchAppendW
#include "include/PathCchAppend.c"
2012-10-18 23:37:00 +04:00
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
/* Unix-style Paths */
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define _PATH_SEPARATOR_STR PATH_SLASH_STR
#define PATH_CCH_APPEND UnixPathCchAppendA
2012-10-18 23:37:00 +04:00
#include "include/PathCchAppend.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define _PATH_SEPARATOR_STR PATH_SLASH_STR_W
#define PATH_CCH_APPEND UnixPathCchAppendW
2012-10-18 23:37:00 +04:00
#include "include/PathCchAppend.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
/* Native-style Paths */
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE FALSE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define _PATH_SEPARATOR_STR PATH_SEPARATOR_STR
#define PATH_CCH_APPEND NativePathCchAppendA
2012-10-18 23:37:00 +04:00
#include "include/PathCchAppend.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define _PATH_SEPARATOR_STR PATH_SEPARATOR_STR_W
#define PATH_CCH_APPEND NativePathCchAppendW
2012-10-18 23:37:00 +04:00
#include "include/PathCchAppend.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_CCH_APPEND
/*
* PathCchAppendEx
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchAppendExA(PSTR pszPath, size_t cchPath, PCSTR pszMore, unsigned long dwFlags)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchAppendExW(PWSTR pszPath, size_t cchPath, PCWSTR pszMore, unsigned long dwFlags)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathCchCanonicalize
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchCanonicalizeA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchCanonicalizeW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathCchCanonicalizeEx
*/
2019-11-06 17:24:51 +03:00
HRESULT PathCchCanonicalizeExA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn,
unsigned long dwFlags)
2012-09-23 06:02:55 +04:00
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
2019-11-06 17:24:51 +03:00
HRESULT PathCchCanonicalizeExW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn,
unsigned long dwFlags)
2012-09-23 06:02:55 +04:00
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathAllocCanonicalize
*/
2012-09-23 06:02:55 +04:00
HRESULT PathAllocCanonicalizeA(PCSTR pszPathIn, unsigned long dwFlags, PSTR* ppszPathOut)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathAllocCanonicalizeW(PCWSTR pszPathIn, unsigned long dwFlags, PWSTR* ppszPathOut)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathCchCombine
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchCombineA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchCombineW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn, PCWSTR pszMore)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathCchCombineEx
*/
2019-11-06 17:24:51 +03:00
HRESULT PathCchCombineExA(PSTR pszPathOut, size_t cchPathOut, PCSTR pszPathIn, PCSTR pszMore,
unsigned long dwFlags)
2012-09-23 06:02:55 +04:00
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
2019-11-06 17:24:51 +03:00
HRESULT PathCchCombineExW(PWSTR pszPathOut, size_t cchPathOut, PCWSTR pszPathIn, PCWSTR pszMore,
unsigned long dwFlags)
2012-09-23 06:02:55 +04:00
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* PathAllocCombine
*/
2012-10-05 07:19:05 +04:00
/* Windows-style Paths */
2012-10-05 07:19:05 +04:00
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_BACKSLASH_CHR
#define _PATH_SEPARATOR_STR PATH_BACKSLASH_STR_W
#define PATH_ALLOC_COMBINE PathAllocCombineW
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
2012-10-05 07:19:05 +04:00
/* Unix-style Paths */
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SLASH_CHR
#define _PATH_SEPARATOR_STR PATH_SLASH_STR_W
#define PATH_ALLOC_COMBINE UnixPathAllocCombineW
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
2012-10-05 07:19:05 +04:00
/* Native-style Paths */
2012-10-05 07:19:05 +04:00
2019-11-06 17:24:51 +03:00
#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
2019-11-06 17:24:51 +03:00
#define DEFINE_UNICODE TRUE
#define _PATH_SEPARATOR_CHR PATH_SEPARATOR_CHR
#define _PATH_SEPARATOR_STR PATH_SEPARATOR_STR_W
#define PATH_ALLOC_COMBINE NativePathAllocCombineW
#include "include/PathAllocCombine.c"
#undef DEFINE_UNICODE
#undef _PATH_SEPARATOR_CHR
#undef _PATH_SEPARATOR_STR
#undef PATH_ALLOC_COMBINE
2012-10-05 07:19:05 +04:00
/**
* PathCchFindExtension
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchFindExtensionA(PCSTR pszPath, size_t cchPath, PCSTR* ppszExt)
{
2019-11-06 17:24:51 +03:00
char* p = (char*)pszPath;
if (!pszPath || !cchPath || !ppszExt)
return E_INVALIDARG;
/* find end of string */
while (*p && --cchPath)
{
p++;
}
if (*p)
{
/* pszPath is not null terminated within the cchPath range */
return E_INVALIDARG;
}
/* If no extension is found, ppszExt must point to the string's terminating null */
*ppszExt = p;
/* search backwards for '.' */
while (p > pszPath)
{
if (*p == '.')
{
2019-11-06 17:24:51 +03:00
*ppszExt = (PCSTR)p;
break;
}
if ((*p == '\\') || (*p == '/') || (*p == ':'))
break;
p--;
}
return S_OK;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchFindExtensionW(PCWSTR pszPath, size_t cchPath, PCWSTR* ppszExt)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchRenameExtension
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchRenameExtensionA(PSTR pszPath, size_t cchPath, PCSTR pszExt)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchRenameExtensionW(PWSTR pszPath, size_t cchPath, PCWSTR pszExt)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchRemoveExtension
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchRemoveExtensionA(PSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchRemoveExtensionW(PWSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchIsRoot
*/
2012-09-23 06:02:55 +04:00
BOOL PathCchIsRootA(PCSTR pszPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
2015-11-03 18:18:09 +03:00
return FALSE;
2012-09-23 06:02:55 +04:00
}
BOOL PathCchIsRootW(PCWSTR pszPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
2015-11-03 18:18:09 +03:00
return FALSE;
2012-09-23 06:02:55 +04:00
}
/**
* PathIsUNCEx
*/
2012-09-23 06:02:55 +04:00
BOOL PathIsUNCExA(PCSTR pszPath, PCSTR* ppszServer)
{
if (!pszPath)
return FALSE;
if ((pszPath[0] == '\\') && (pszPath[1] == '\\'))
{
*ppszServer = &pszPath[2];
return TRUE;
}
return FALSE;
2012-09-23 06:02:55 +04:00
}
BOOL PathIsUNCExW(PCWSTR pszPath, PCWSTR* ppszServer)
{
if (!pszPath)
return FALSE;
if ((pszPath[0] == '\\') && (pszPath[1] == '\\'))
{
*ppszServer = &pszPath[2];
return TRUE;
}
return FALSE;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchSkipRoot
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchSkipRootA(PCSTR pszPath, PCSTR* ppszRootEnd)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchSkipRootW(PCWSTR pszPath, PCWSTR* ppszRootEnd)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchStripToRoot
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchStripToRootA(PSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchStripToRootW(PWSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchStripPrefix
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchStripPrefixA(PSTR pszPath, size_t cchPath)
{
2012-10-05 22:45:54 +04:00
BOOL hasPrefix;
if (!pszPath)
return E_INVALIDARG;
2012-10-05 22:45:54 +04:00
if (cchPath < 4 || cchPath > PATHCCH_MAX_CCH)
return E_INVALIDARG;
2012-10-05 22:45:54 +04:00
2019-11-06 17:24:51 +03:00
hasPrefix = ((pszPath[0] == '\\') && (pszPath[1] == '\\') && (pszPath[2] == '?') &&
(pszPath[3] == '\\'))
? TRUE
: FALSE;
2012-10-05 22:45:54 +04:00
if (hasPrefix)
{
if (cchPath < 6)
2012-10-05 22:45:54 +04:00
return S_FALSE;
if (IsCharAlpha(pszPath[4]) && (pszPath[5] == ':')) /* like C: */
2012-10-05 22:45:54 +04:00
{
memmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4);
/* since the passed pszPath must not necessarily be null terminated
* and we always have enough space after the strip we can always
* ensure the null termination of the stripped result
*/
pszPath[cchPath - 4] = 0;
2012-10-05 22:45:54 +04:00
return S_OK;
}
}
return S_FALSE;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchStripPrefixW(PWSTR pszPath, size_t cchPath)
{
BOOL hasPrefix;
if (!pszPath)
return E_INVALIDARG;
if (cchPath < 4 || cchPath > PATHCCH_MAX_CCH)
return E_INVALIDARG;
2019-11-06 17:24:51 +03:00
hasPrefix = ((pszPath[0] == '\\') && (pszPath[1] == '\\') && (pszPath[2] == '?') &&
(pszPath[3] == '\\'))
? TRUE
: FALSE;
if (hasPrefix)
{
2019-02-07 16:35:58 +03:00
int rc;
if (cchPath < 6)
return S_FALSE;
2019-02-07 16:35:58 +03:00
rc = (lstrlenW(&pszPath[4]) + 1);
if ((rc < 0) || ((INT64)cchPath < rc))
return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
2019-02-08 11:20:58 +03:00
if (IsCharAlphaW(pszPath[4]) && (pszPath[5] == L':')) /* like C: */
{
wmemmove_s(pszPath, cchPath, &pszPath[4], cchPath - 4);
/* since the passed pszPath must not necessarily be null terminated
* and we always have enough space after the strip we can always
* ensure the null termination of the stripped result
*/
pszPath[cchPath - 4] = 0;
return S_OK;
}
}
return S_FALSE;
2012-09-23 06:02:55 +04:00
}
/**
* PathCchRemoveFileSpec
*/
2012-09-23 06:02:55 +04:00
HRESULT PathCchRemoveFileSpecA(PSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
HRESULT PathCchRemoveFileSpecW(PWSTR pszPath, size_t cchPath)
{
WLog_ERR(TAG, "%s: not implemented", __FUNCTION__);
return E_NOTIMPL;
2012-09-23 06:02:55 +04:00
}
/*
* Path Portability Functions
*/
/**
* PathCchConvertStyle
*/
HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags)
{
2012-10-17 15:48:24 +04:00
size_t index;
2013-03-22 23:52:43 +04:00
if (dwFlags == PATH_STYLE_WINDOWS)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_SLASH_CHR)
pszPath[index] = PATH_BACKSLASH_CHR;
}
}
2013-03-22 23:52:43 +04:00
else if (dwFlags == PATH_STYLE_UNIX)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_BACKSLASH_CHR)
pszPath[index] = PATH_SLASH_CHR;
}
}
2013-03-22 23:52:43 +04:00
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 E_FAIL;
}
}
else
{
/* Gangnam style? */
return E_FAIL;
}
return S_OK;
}
HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlags)
{
2012-10-17 15:48:24 +04:00
size_t index;
2013-03-22 23:52:43 +04:00
if (dwFlags == PATH_STYLE_WINDOWS)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_SLASH_CHR)
pszPath[index] = PATH_BACKSLASH_CHR;
}
}
2013-03-22 23:52:43 +04:00
else if (dwFlags == PATH_STYLE_UNIX)
{
for (index = 0; index < cchPath; index++)
{
if (pszPath[index] == PATH_BACKSLASH_CHR)
pszPath[index] = PATH_SLASH_CHR;
}
}
2013-03-22 23:52:43 +04:00
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 E_FAIL;
}
}
else
{
/* Gangnam style? */
return E_FAIL;
}
return S_OK;
}
/**
* PathGetSeparator
*/
char PathGetSeparatorA(unsigned long dwFlags)
{
char separator = PATH_SEPARATOR_CHR;
if (!dwFlags)
dwFlags = PATH_STYLE_NATIVE;
if (dwFlags == PATH_STYLE_WINDOWS)
separator = PATH_SEPARATOR_CHR;
else if (dwFlags == PATH_STYLE_UNIX)
separator = PATH_SEPARATOR_CHR;
else if (dwFlags == PATH_STYLE_NATIVE)
separator = PATH_SEPARATOR_CHR;
return separator;
}
WCHAR PathGetSeparatorW(unsigned long dwFlags)
{
WCHAR separator = PATH_SEPARATOR_CHR;
if (!dwFlags)
dwFlags = PATH_STYLE_NATIVE;
if (dwFlags == PATH_STYLE_WINDOWS)
separator = PATH_SEPARATOR_CHR;
else if (dwFlags == PATH_STYLE_UNIX)
separator = PATH_SEPARATOR_CHR;
else if (dwFlags == PATH_STYLE_NATIVE)
separator = PATH_SEPARATOR_CHR;
return separator;
}
/**
* PathGetSharedLibraryExtension
*/
static const CHAR SharedLibraryExtensionDllA[] = "dll";
static const CHAR SharedLibraryExtensionSoA[] = "so";
static const CHAR SharedLibraryExtensionDylibA[] = "dylib";
2019-11-06 17:24:51 +03:00
static const WCHAR SharedLibraryExtensionDllW[] = { 'd', 'l', 'l', '\0' };
static const WCHAR SharedLibraryExtensionSoW[] = { 's', 'o', '\0' };
static const WCHAR SharedLibraryExtensionDylibW[] = { 'd', 'y', 'l', 'i', 'b', '\0' };
static const CHAR SharedLibraryExtensionDotDllA[] = ".dll";
static const CHAR SharedLibraryExtensionDotSoA[] = ".so";
static const CHAR SharedLibraryExtensionDotDylibA[] = ".dylib";
2019-11-06 17:24:51 +03:00
static const WCHAR SharedLibraryExtensionDotDllW[] = { '.', 'd', 'l', 'l', '\0' };
static const WCHAR SharedLibraryExtensionDotSoW[] = { '.', 's', 'o', '\0' };
static const WCHAR SharedLibraryExtensionDotDylibW[] = { '.', 'd', 'y', 'l', 'i', 'b', '\0' };
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 defined(__APPLE__)
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionDotSoA;
else
return SharedLibraryExtensionDotDylibA;
#else
return SharedLibraryExtensionDotSoA;
#endif
}
else
{
#ifdef _WIN32
return SharedLibraryExtensionDllA;
#elif defined(__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 defined(__APPLE__)
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionDotSoW;
else
return SharedLibraryExtensionDotDylibW;
#else
return SharedLibraryExtensionDotSoW;
#endif
}
else
{
#ifdef _WIN32
return SharedLibraryExtensionDllW;
#elif defined(__APPLE__)
if (dwFlags & PATH_SHARED_LIB_EXT_APPLE_SO)
return SharedLibraryExtensionSoW;
else
return SharedLibraryExtensionDylibW;
#else
return SharedLibraryExtensionSoW;
#endif
}
return NULL;
}