#define STAT_TIME_TO_FILETIME(_t) (((UINT64)(_t) + EPOCH_DIFF) * 10000000LL)
-static wArrayList *_HandleCreators;
+static wArrayList* _HandleCreators;
static pthread_once_t _HandleCreatorsInitialized = PTHREAD_ONCE_INIT;
-HANDLE_CREATOR *GetNamedPipeClientHandleCreator(void);
+HANDLE_CREATOR* GetNamedPipeClientHandleCreator(void);
#if defined __linux__ && !defined ANDROID
-HANDLE_CREATOR *GetCommHandleCreator(void);
+HANDLE_CREATOR* GetCommHandleCreator(void);
#endif /* __linux__ && !defined ANDROID */
static void _HandleCreatorsInit()
{
-
assert(_HandleCreators == NULL);
_HandleCreators = ArrayList_New(TRUE);
+
if (!_HandleCreators)
return;
#endif /* HAVE_AIO_H */
-HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
+HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
int i;
ArrayList_Lock(_HandleCreators);
- for (i=0; i <= ArrayList_Count(_HandleCreators); i++)
+ for (i = 0; i <= ArrayList_Count(_HandleCreators); i++)
{
HANDLE_CREATOR* creator = ArrayList_GetItem(_HandleCreators, i);
if (creator && creator->IsHandled(lpFileName))
{
HANDLE newHandle = creator->CreateFileA(lpFileName, dwDesiredAccess,
- dwShareMode, lpSecurityAttributes, dwCreationDisposition,
- dwFlagsAndAttributes, hTemplateFile);
+ dwShareMode, lpSecurityAttributes, dwCreationDisposition,
+ dwFlagsAndAttributes, hTemplateFile);
ArrayList_Unlock(_HandleCreators);
return newHandle;
}
return INVALID_HANDLE_VALUE;
}
-HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
+HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
+ LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+ DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
LPSTR lpFileNameA = NULL;
HANDLE hdl;
if (ConvertFromUnicode(CP_UTF8, 0, lpFileName, -1, &lpFileNameA, 0, NULL, NULL) < 1)
return NULL;
- hdl= CreateFileA(lpFileNameA, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
- dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
- free (lpFileNameA);
-
+ hdl = CreateFileA(lpFileNameA, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
+ dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
+ free(lpFileNameA);
return hdl;
}
if (ConvertFromUnicode(CP_UTF8, 0, lpFileName, -1, &lpFileNameA, 0, NULL, NULL) < 1)
return FALSE;
- rc = DeleteFileA(lpFileNameA);
- free (lpFileNameA);
+ rc = DeleteFileA(lpFileNameA);
+ free(lpFileNameA);
return rc;
}
BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
- LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
+ LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->ReadFile)
return handle->ops->ReadFile(handle, lpBuffer, nNumberOfBytesToRead,
- lpNumberOfBytesRead, lpOverlapped);
+ lpNumberOfBytesRead, lpOverlapped);
WLog_ERR(TAG, "ReadFile operation not implemented");
return FALSE;
}
BOOL ReadFileEx(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
- LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
+ LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->ReadFileEx)
return handle->ops->ReadFileEx(handle, lpBuffer, nNumberOfBytesToRead,
- lpOverlapped, lpCompletionRoutine);
+ lpOverlapped, lpCompletionRoutine);
WLog_ERR(TAG, "ReadFileEx operation not implemented");
return FALSE;
-
return TRUE;
}
BOOL ReadFileScatter(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[],
- DWORD nNumberOfBytesToRead, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped)
+ DWORD nNumberOfBytesToRead, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->ReadFileScatter)
return handle->ops->ReadFileScatter(handle, aSegmentArray, nNumberOfBytesToRead,
- lpReserved, lpOverlapped);
+ lpReserved, lpOverlapped);
WLog_ERR(TAG, "ReadFileScatter operation not implemented");
return FALSE;
}
BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
- LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
+ LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->WriteFile)
return handle->ops->WriteFile(handle, lpBuffer, nNumberOfBytesToWrite,
- lpNumberOfBytesWritten, lpOverlapped);
+ lpNumberOfBytesWritten, lpOverlapped);
WLog_ERR(TAG, "WriteFile operation not implemented");
return FALSE;
}
BOOL WriteFileEx(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
- LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
+ LPOVERLAPPED lpOverlapped, LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->WriteFileEx)
return handle->ops->WriteFileEx(handle, lpBuffer, nNumberOfBytesToWrite,
- lpOverlapped, lpCompletionRoutine);
+ lpOverlapped, lpCompletionRoutine);
WLog_ERR(TAG, "WriteFileEx operation not implemented");
return FALSE;
}
BOOL WriteFileGather(HANDLE hFile, FILE_SEGMENT_ELEMENT aSegmentArray[],
- DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped)
+ DWORD nNumberOfBytesToWrite, LPDWORD lpReserved, LPOVERLAPPED lpOverlapped)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->WriteFileGather)
return handle->ops->WriteFileGather(handle, aSegmentArray, nNumberOfBytesToWrite,
- lpReserved, lpOverlapped);
+ lpReserved, lpOverlapped);
WLog_ERR(TAG, "WriteFileGather operation not implemented");
return FALSE;
BOOL FlushFileBuffers(HANDLE hFile)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->FlushFileBuffers)
return handle->ops->FlushFileBuffers(handle);
return FALSE;
FindClose(hFind);
-
fd->dwFileAttributes = findFileData.dwFileAttributes;
fd->ftCreationTime = findFileData.ftCreationTime;
fd->ftLastAccessTime = findFileData.ftLastAccessTime;
return FALSE;
}
- ret = SetFileAttributesA(lpCFileName,dwFileAttributes);
+ ret = SetFileAttributesA(lpCFileName, dwFileAttributes);
free(lpCFileName);
return ret;
}
BOOL SetEndOfFile(HANDLE hFile)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->SetEndOfFile)
return handle->ops->SetEndOfFile(handle);
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->GetFileSize)
return handle->ops->GetFileSize(handle, lpFileSizeHigh);
}
DWORD SetFilePointer(HANDLE hFile, LONG lDistanceToMove,
- PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
+ PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->SetFilePointer)
return handle->ops->SetFilePointer(handle, lDistanceToMove,
- lpDistanceToMoveHigh, dwMoveMethod);
+ lpDistanceToMoveHigh, dwMoveMethod);
WLog_ERR(TAG, "SetFilePointer operation not implemented");
return 0;
}
BOOL SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove,
- PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
+ PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->SetFilePointerEx)
return handle->ops->SetFilePointerEx(handle, liDistanceToMove,
- lpNewFilePointer, dwMoveMethod);
+ lpNewFilePointer, dwMoveMethod);
WLog_ERR(TAG, "SetFilePointerEx operation not implemented");
return 0;
}
BOOL LockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
- DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh)
+ DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->LockFile)
return handle->ops->LockFile(handle, dwFileOffsetLow, dwFileOffsetHigh,
- nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh);
+ nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh);
WLog_ERR(TAG, "LockFile operation not implemented");
return FALSE;
}
BOOL LockFileEx(HANDLE hFile, DWORD dwFlags, DWORD dwReserved,
- DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped)
+ DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh, LPOVERLAPPED lpOverlapped)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->LockFileEx)
return handle->ops->LockFileEx(handle, dwFlags, dwReserved,
- nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, lpOverlapped);
+ nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh, lpOverlapped);
WLog_ERR(TAG, "LockFileEx operation not implemented");
return FALSE;
}
BOOL UnlockFile(HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHigh,
- DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh)
+ DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->UnlockFile)
return handle->ops->UnlockFile(handle, dwFileOffsetLow, dwFileOffsetHigh,
- nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh);
+ nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh);
WLog_ERR(TAG, "UnLockFile operation not implemented");
return FALSE;
}
BOOL UnlockFileEx(HANDLE hFile, DWORD dwReserved, DWORD nNumberOfBytesToUnlockLow,
- DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped)
+ DWORD nNumberOfBytesToUnlockHigh, LPOVERLAPPED lpOverlapped)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->UnlockFileEx)
return handle->ops->UnlockFileEx(handle, dwReserved,
- nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped);
+ nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh, lpOverlapped);
WLog_ERR(TAG, "UnLockFileEx operation not implemented");
return FALSE;
}
-BOOL WINAPI SetFileTime(HANDLE hFile, const FILETIME *lpCreationTime,
- const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)
+BOOL WINAPI SetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
+ const FILETIME* lpLastAccessTime, const FILETIME* lpLastWriteTime)
{
ULONG Type;
- WINPR_HANDLE *handle;
+ WINPR_HANDLE* handle;
if (hFile == INVALID_HANDLE_VALUE)
return FALSE;
if (!winpr_Handle_GetInfo(hFile, &Type, &handle))
return FALSE;
- handle = (WINPR_HANDLE *)hFile;
+ handle = (WINPR_HANDLE*)hFile;
+
if (handle->ops->SetFileTime)
return handle->ops->SetFileTime(handle, lpCreationTime,
- lpLastAccessTime, lpLastWriteTime);
+ lpLastAccessTime, lpLastWriteTime);
WLog_ERR(TAG, "%s operation not implemented", __FUNCTION__);
return FALSE;
WIN32_FILE_SEARCH* pFileSearch;
ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
pFileSearch = (WIN32_FILE_SEARCH*) calloc(1, sizeof(WIN32_FILE_SEARCH));
+
if (!pFileSearch)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return INVALID_HANDLE_VALUE;
}
+
/* Separate lpFileName into path and pattern components */
p = strrchr(lpFileName, '/');
index = (p - lpFileName);
length = (p - lpFileName);
pFileSearch->lpPath = (LPSTR) malloc(length + 1);
+
if (!pFileSearch->lpPath)
{
free(pFileSearch);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return INVALID_HANDLE_VALUE;
}
+
CopyMemory(pFileSearch->lpPath, lpFileName, length);
pFileSearch->lpPath[length] = '\0';
length = strlen(lpFileName) - index;
pFileSearch->lpPattern = (LPSTR) malloc(length + 1);
+
if (!pFileSearch->lpPattern)
{
free(pFileSearch->lpPath);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return INVALID_HANDLE_VALUE;
}
+
CopyMemory(pFileSearch->lpPattern, &lpFileName[index + 1], length);
pFileSearch->lpPattern[length] = '\0';
return INVALID_HANDLE_VALUE;
}
+static BOOL ConvertFindDataAToW(LPWIN32_FIND_DATAA lpFindFileDataA,
+ LPWIN32_FIND_DATAW lpFindFileDataW)
+{
+ int length;
+ WCHAR* unicodeFileName;
+
+ if (!lpFindFileDataA || !lpFindFileDataW)
+ return FALSE;
+
+ lpFindFileDataW->dwFileAttributes = lpFindFileDataA->dwFileAttributes;
+ lpFindFileDataW->ftCreationTime = lpFindFileDataA->ftCreationTime;
+ lpFindFileDataW->ftLastAccessTime = lpFindFileDataA->ftLastAccessTime;
+ lpFindFileDataW->ftLastWriteTime = lpFindFileDataA->ftLastWriteTime;
+ lpFindFileDataW->nFileSizeHigh = lpFindFileDataA->nFileSizeHigh;
+ lpFindFileDataW->nFileSizeLow = lpFindFileDataA->nFileSizeLow;
+ lpFindFileDataW->dwReserved0 = lpFindFileDataA->dwReserved0;
+ lpFindFileDataW->dwReserved1 = lpFindFileDataA->dwReserved1;
+ unicodeFileName = NULL;
+ length = ConvertToUnicode(CP_UTF8, 0, lpFindFileDataA->cFileName, -1, &unicodeFileName, 0) * 2;
+
+ if (length == 0)
+ return FALSE;
+
+ if (length > MAX_PATH)
+ length = MAX_PATH;
+
+ CopyMemory(lpFindFileDataW->cFileName, unicodeFileName, length);
+ free(unicodeFileName);
+ length = ConvertToUnicode(CP_UTF8, 0, lpFindFileDataA->cAlternateFileName,
+ -1, &unicodeFileName, 0) * 2;
+
+ if (length == 0)
+ return TRUE;
+
+ if (length > 14)
+ length = 14;
+
+ CopyMemory(lpFindFileDataW->cAlternateFileName, unicodeFileName, length);
+ free(unicodeFileName);
+ return TRUE;
+}
+
HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
{
char* utfFileName = NULL;
HANDLE h;
- WCHAR* unicodeFileName;
- int length;
+ LPWIN32_FIND_DATAA fd = (LPWIN32_FIND_DATAA)calloc(1, sizeof(WIN32_FIND_DATAA));
- LPWIN32_FIND_DATAA fd = (LPWIN32_FIND_DATAA)malloc(sizeof(WIN32_FIND_DATAA));
if (!fd)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
if (h != INVALID_HANDLE_VALUE)
{
- CopyMemory(lpFindFileData, fd, 352);
-
- unicodeFileName = NULL;
- length = ConvertToUnicode(CP_UTF8, 0, fd->cFileName, -1, &unicodeFileName, 0) * 2;
- if (length == 0)
+ if (!ConvertFindDataAToW(fd, lpFindFileData))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
free(fd);
return INVALID_HANDLE_VALUE;
}
- CopyMemory(&lpFindFileData->cFileName, unicodeFileName, length);
- free(unicodeFileName);
}
return h;
}
HANDLE FindFirstFileExA(LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, LPVOID lpFindFileData,
- FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, DWORD dwAdditionalFlags)
+ FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, DWORD dwAdditionalFlags)
{
return INVALID_HANDLE_VALUE;
}
HANDLE FindFirstFileExW(LPCWSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId, LPVOID lpFindFileData,
- FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, DWORD dwAdditionalFlags)
+ FINDEX_SEARCH_OPS fSearchOp, LPVOID lpSearchFilter, DWORD dwAdditionalFlags)
{
return INVALID_HANDLE_VALUE;
}
int pathlen;
int namelen;
UINT64 ft;
-
ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAA));
if (!hFindFile)
{
strcpy(lpFindFileData->cFileName, pFileSearch->pDirent->d_name);
namelen = strlen(lpFindFileData->cFileName);
-
pathlen = strlen(pFileSearch->lpPath);
fullpath = (char*)malloc(pathlen + namelen + 2);
+
if (fullpath == NULL)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
+
memcpy(fullpath, pFileSearch->lpPath, pathlen);
fullpath[pathlen] = '/';
memcpy(fullpath + pathlen + 1, pFileSearch->pDirent->d_name, namelen);
- fullpath[pathlen+namelen+1] = 0;
+ fullpath[pathlen + namelen + 1] = 0;
if (stat(fullpath, &fileStat) != 0)
{
}
free(fullpath);
-
lpFindFileData->dwFileAttributes = 0;
if (S_ISDIR(fileStat.st_mode))
lpFindFileData->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
if (pFileSearch->pDirent->d_name[0] == '.' && namelen != 1 &&
- (pFileSearch->pDirent->d_name[1] != '.' && namelen != 2))
+ (pFileSearch->pDirent->d_name[1] != '.' && namelen != 2))
lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;
- if (! (fileStat.st_mode & S_IWUSR))
+ if (!(fileStat.st_mode & S_IWUSR))
lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
#ifdef _DARWIN_FEATURE_64_BIT_INODE
#endif
lpFindFileData->ftCreationTime.dwHighDateTime = ft >> 32;
lpFindFileData->ftCreationTime.dwLowDateTime = ft & 0xFFFFFFFF;
-
ft = STAT_TIME_TO_FILETIME(fileStat.st_mtime);
lpFindFileData->ftLastWriteTime.dwHighDateTime = ft >> 32;
lpFindFileData->ftCreationTime.dwLowDateTime = ft & 0xFFFFFFFF;
-
ft = STAT_TIME_TO_FILETIME(fileStat.st_atime);
lpFindFileData->ftLastAccessTime.dwHighDateTime = ft >> 32;
lpFindFileData->ftLastAccessTime.dwLowDateTime = ft & 0xFFFFFFFF;
-
lpFindFileData->nFileSizeHigh = fileStat.st_size >> 32;
lpFindFileData->nFileSizeLow = fileStat.st_size & 0xFFFFFFFF;
-
return TRUE;
}
}
BOOL FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)
{
- WCHAR* unicodeFileName;
- int length;
+ LPWIN32_FIND_DATAA fd = (LPWIN32_FIND_DATAA)calloc(1, sizeof(WIN32_FIND_DATAA));
- LPWIN32_FIND_DATAA fd = (LPWIN32_FIND_DATAA)malloc(sizeof(WIN32_FIND_DATAA));
if (!fd)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
if (FindNextFileA(hFindFile, fd))
{
- CopyMemory(lpFindFileData, fd, 352);
-
- unicodeFileName = NULL;
- length = ConvertToUnicode(CP_UTF8, 0, fd->cFileName, -1, &unicodeFileName, 0) * 2;
- if (length == 0)
+ if (!ConvertFindDataAToW(fd, lpFindFileData))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
free(fd);
return FALSE;
}
- CopyMemory(&lpFindFileData->cFileName, unicodeFileName, length);
- free(unicodeFileName);
- free(fd);
+ free(fd);
return TRUE;
}
BOOL RemoveDirectoryA(LPCSTR lpPathName)
{
int ret = rmdir(lpPathName);
+
if (ret != 0)
SetLastError(map_posix_err(errno));
else
SetLastError(STATUS_SUCCESS);
+
return ret == 0;
}
LPSTR lpCExistingFileName;
LPSTR lpCNewFileName;
BOOL ret;
- if (ConvertFromUnicode(CP_UTF8, 0, lpExistingFileName, -1, &lpCExistingFileName, 0, NULL, NULL) <= 0)
+
+ if (ConvertFromUnicode(CP_UTF8, 0, lpExistingFileName, -1, &lpCExistingFileName, 0, NULL,
+ NULL) <= 0)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
return chmod(filename, fl);
#else
int rc;
- WCHAR *wfl = NULL;
-
+ WCHAR* wfl = NULL;
int fl = 0;
if (ConvertToUnicode(CP_UTF8, 0, filename, -1, &wfl, 0) <= 0)
WLog_WARN(TAG, "Unsupported file mode %d for _wchmod", flags);
rc = _wchmod(wfl, flags);
- free (wfl);
+ free(wfl);
return rc;
#endif
}