/* Path was entered as secondary argument, swap */
if (PathFileExistsA(name))
{
- const char* tmp = path;
- path = name;
- name = tmp;
+ if (!PathFileExistsA(path) || (!PathIsRelativeA(name) && PathIsRelativeA(path)))
+ {
+ const char* tmp = path;
+ path = name;
+ name = tmp;
+ }
}
}
#if !defined(_WIN32) || defined(_UWP)
+WINPR_API BOOL PathIsRelativeA(LPCSTR pszPath);
+WINPR_API BOOL PathIsRelativeW(LPCWSTR pszPath);
+
WINPR_API BOOL PathFileExistsA(LPCSTR pszPath);
WINPR_API BOOL PathFileExistsW(LPCWSTR pszPath);
#if !defined(_WIN32) || defined(_UWP)
+BOOL PathIsRelativeA(LPCSTR pszPath)
+{
+ if (!pszPath)
+ return FALSE;
+
+ return pszPath[0] != '/';
+}
+
+BOOL PathIsRelativeW(LPCWSTR pszPath)
+{
+ LPSTR lpFileNameA = NULL;
+ BOOL ret;
+
+ if (ConvertFromUnicode(CP_UTF8, 0, pszPath, -1, &lpFileNameA, 0, NULL, NULL) < 1)
+ return FALSE;
+
+ ret = PathIsRelativeA(lpFileNameA);
+ free(lpFileNameA);
+ return ret;
+}
+
BOOL PathFileExistsA(LPCSTR pszPath)
{
struct stat stat_info;