diff options
author | Karlson2k <k2k@narod.ru> | 2014-10-19 22:45:04 +0400 |
---|---|---|
committer | Karlson2k <k2k@narod.ru> | 2014-10-19 22:45:04 +0400 |
commit | 8e4bfa788e3c56d50f058955317f5f72e0f68d52 (patch) | |
tree | 0f8fb5896a1560b251c3a465dd077d823d36d3c5 | |
parent | b900f10140d2cdf9d8719e7d0f05a0fcc865368f (diff) | |
parent | e502b0993760b3e8b001f0360755a424bab79086 (diff) |
Merge pull request #5534 from Karlson2k/fix_vfs_and_emu_01
Better emulate system read() and fread() functions, fixes #15490
-rw-r--r-- | xbmc/cores/DllLoader/exports/emu_msvcrt.cpp | 2 | ||||
-rw-r--r-- | xbmc/filesystem/File.cpp | 8 | ||||
-rw-r--r-- | xbmc/filesystem/posix/PosixFile.cpp | 14 | ||||
-rw-r--r-- | xbmc/filesystem/win32/Win32File.cpp | 14 |
4 files changed, 27 insertions, 11 deletions
diff --git a/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp b/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp index 5bde82e71e..58474d25d3 100644 --- a/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp +++ b/xbmc/cores/DllLoader/exports/emu_msvcrt.cpp @@ -530,7 +530,7 @@ extern "C" if (bWrite) bResult = pFile->OpenForWrite(CUtil::ValidatePath(str), bOverwrite); else - bResult = pFile->Open(CUtil::ValidatePath(str)); + bResult = pFile->Open(CUtil::ValidatePath(str), READ_TRUNCATED); if (bResult) { diff --git a/xbmc/filesystem/File.cpp b/xbmc/filesystem/File.cpp index 0468b79b2c..c4ac83372e 100644 --- a/xbmc/filesystem/File.cpp +++ b/xbmc/filesystem/File.cpp @@ -497,7 +497,9 @@ int CFile::Stat(const CURL& file, struct __stat64* buffer) ssize_t CFile::Read(void *lpBuf, size_t uiBufSize) { - if (!m_pFile || !lpBuf) + if (!m_pFile) + return -1; + if (lpBuf == NULL && uiBufSize != 0) return -1; if (uiBufSize > SSIZE_MAX) @@ -743,7 +745,9 @@ bool CFile::ReadString(char *szLine, int iLineLength) ssize_t CFile::Write(const void* lpBuf, size_t uiBufSize) { - if (!m_pFile || !lpBuf) + if (!m_pFile) + return -1; + if (lpBuf == NULL && uiBufSize != 0) return -1; try diff --git a/xbmc/filesystem/posix/PosixFile.cpp b/xbmc/filesystem/posix/PosixFile.cpp index b59e7dc957..35909a01c8 100644 --- a/xbmc/filesystem/posix/PosixFile.cpp +++ b/xbmc/filesystem/posix/PosixFile.cpp @@ -113,10 +113,13 @@ void CPosixFile::Close() ssize_t CPosixFile::Read(void* lpBuf, size_t uiBufSize) { - assert(lpBuf != NULL); - if (m_fd < 0 || !lpBuf) + if (m_fd < 0) return -1; + assert(lpBuf != NULL || uiBufSize == 0); + if (lpBuf == NULL && uiBufSize != 0) + return -1; + if (uiBufSize > SSIZE_MAX) uiBufSize = SSIZE_MAX; @@ -152,8 +155,11 @@ ssize_t CPosixFile::Read(void* lpBuf, size_t uiBufSize) ssize_t CPosixFile::Write(const void* lpBuf, size_t uiBufSize) { - assert(lpBuf != NULL); - if (m_fd < 0 || !m_allowWrite || !lpBuf) + if (m_fd < 0) + return -1; + + assert(lpBuf != NULL || uiBufSize == 0); + if ((lpBuf == NULL && uiBufSize != 0) || !m_allowWrite) return -1; if (uiBufSize > SSIZE_MAX) diff --git a/xbmc/filesystem/win32/Win32File.cpp b/xbmc/filesystem/win32/Win32File.cpp index 7b927a007d..dfc5babe6b 100644 --- a/xbmc/filesystem/win32/Win32File.cpp +++ b/xbmc/filesystem/win32/Win32File.cpp @@ -173,8 +173,11 @@ void CWin32File::Close() ssize_t CWin32File::Read(void* lpBuf, size_t uiBufSize) { - assert(lpBuf != NULL); - if (m_hFile == INVALID_HANDLE_VALUE || !lpBuf) + if (m_hFile == INVALID_HANDLE_VALUE) + return -1; + + assert(lpBuf != NULL || uiBufSize == 0); + if (lpBuf == NULL && uiBufSize != 0) return -1; if (uiBufSize > SSIZE_MAX) @@ -211,8 +214,11 @@ ssize_t CWin32File::Read(void* lpBuf, size_t uiBufSize) ssize_t CWin32File::Write(const void* lpBuf, size_t uiBufSize) { - assert(lpBuf != NULL); - if (m_hFile == INVALID_HANDLE_VALUE || !lpBuf) + if (m_hFile == INVALID_HANDLE_VALUE) + return -1; + + assert(lpBuf != NULL || uiBufSize == 0); + if (lpBuf == NULL && uiBufSize != 0) return -1; if (!m_allowWrite) |