diff --git a/channels/drive/client/drive_file.c b/channels/drive/client/drive_file.c index 0e62736db..b077da1f8 100644 --- a/channels/drive/client/drive_file.c +++ b/channels/drive/client/drive_file.c @@ -578,7 +578,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN if (file->file_handle == INVALID_HANDLE_VALUE) { - WLog_ERR(TAG, "Unable to set file time %s (%d)", file->fullpath, GetLastError()); + WLog_ERR(TAG, "Unable to set file time %s (%"PRId32")", file->fullpath, GetLastError()); return FALSE; } @@ -614,7 +614,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN if (!SetFileTime(file->file_handle, pftCreationTime, pftLastAccessTime, pftLastWriteTime)) { - WLog_ERR(TAG, "Unable to set file time %s to %d", file->fullpath); + WLog_ERR(TAG, "Unable to set file time to %s", file->fullpath); return FALSE; } @@ -630,7 +630,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN if (file->file_handle == INVALID_HANDLE_VALUE) { - WLog_ERR(TAG, "Unable to truncate %s to %"PRId64" (%d)", file->fullpath, size, GetLastError()); + WLog_ERR(TAG, "Unable to truncate %s to %"PRId64" (%"PRId32")", file->fullpath, size, GetLastError()); return FALSE; } @@ -639,7 +639,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN if (SetFilePointer(file->file_handle, liSize.LowPart, &liSize.HighPart, FILE_BEGIN) == INVALID_SET_FILE_POINTER) { - WLog_ERR(TAG, "Unable to truncate %s to %d (%d)", file->fullpath, size, GetLastError()); + WLog_ERR(TAG, "Unable to truncate %s to %d (%"PRId32")", file->fullpath, size, GetLastError()); return FALSE; } @@ -647,7 +647,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN if (SetEndOfFile(file->file_handle) == 0) { - WLog_ERR(TAG, "Unable to truncate %s to %d (%d)", file->fullpath, size, GetLastError()); + WLog_ERR(TAG, "Unable to truncate %s to %d (%"PRId32")", file->fullpath, size, GetLastError()); return FALSE; } diff --git a/channels/drive/client/drive_main.c b/channels/drive/client/drive_main.c index 54d7e4421..827244698 100644 --- a/channels/drive/client/drive_main.c +++ b/channels/drive/client/drive_main.c @@ -124,7 +124,7 @@ static DWORD drive_map_windows_err(DWORD fs_errno) default: rc = STATUS_UNSUCCESSFUL; - WLog_ERR(TAG, "Error code not found: %d", fs_errno); + WLog_ERR(TAG, "Error code not found: %"PRId32"", fs_errno); break; } diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c index b112e2eae..aa70212b7 100644 --- a/winpr/libwinpr/crt/string.c +++ b/winpr/libwinpr/crt/string.c @@ -136,6 +136,9 @@ WCHAR* _wcsrchr(const WCHAR* str, WCHAR c) WCHAR *p; WCHAR ch; + if (!str) + return NULL; + for (p = (WCHAR *) 0; (ch = *str); str++) if (ch == c) p = (WCHAR *) str; diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index af4f6f9d3..192ee6e13 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -105,7 +105,7 @@ static BOOL FileSetEndOfFile(HANDLE hFile) return FALSE; size = ftell(pFile->fp); - errno = 0; + if (ftruncate(fileno(pFile->fp), size) < 0) { WLog_ERR(TAG, "ftruncate %s failed with %s [0x%08X]", @@ -171,10 +171,10 @@ static BOOL FileRead(PVOID Object, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, return FALSE; file = (WINPR_FILE *)Object; - errno = 0; + clearerr(file->fp); io_status = fread(lpBuffer, 1, nNumberOfBytesToRead, file->fp); - if (io_status == 0 && errno != 0) + if (io_status == 0 && ferror(file->fp)) { status = FALSE; @@ -212,9 +212,9 @@ static BOOL FileWrite(PVOID Object, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrit file = (WINPR_FILE *)Object; - errno = 0; + clearerr(file->fp); io_status = fwrite(lpBuffer, 1, nNumberOfBytesToWrite, file->fp); - if (io_status == 0 && errno != 0) + if (io_status == 0 && ferror(file->fp)) { SetLastError(map_posix_err(errno)); return FALSE; diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c index 785197fc9..39a5e5642 100644 --- a/winpr/libwinpr/path/shell.c +++ b/winpr/libwinpr/path/shell.c @@ -525,7 +525,7 @@ BOOL PathIsDirectoryEmptyA(LPCSTR pszPath) int empty = 1; DIR *dir = opendir(pszPath); - if (dir == NULL) //Not a directory or doesn't exist + if (dir == NULL) /* Not a directory or doesn't exist */ return 1; while ((dp = readdir(dir)) != NULL) {