|
|
@@ -26,6 +26,8 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
#include "OsFile.h"
|
|
|
#include "Assert.h"
|
|
|
+#include "OS.h"
|
|
|
+#include "tchar.h"
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
@@ -35,13 +37,13 @@ OsFile::OsFile(const char* path, FileOpenMode mode) :
|
|
|
{
|
|
|
m_file_handle = CreateFile(path,
|
|
|
mode == FOM_READ ? GENERIC_READ : GENERIC_WRITE,
|
|
|
- FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
+ 0,
|
|
|
NULL,
|
|
|
- OPEN_EXISTING,
|
|
|
+ OPEN_ALWAYS,
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
NULL);
|
|
|
|
|
|
- CE_ASSERT(m_file_handle != NULL || m_file_handle != INVALID_HANDLE_VALUE, "Unable to open file: %s", path);
|
|
|
+ CE_ASSERT(m_file_handle != INVALID_HANDLE_VALUE, "Unable to open file: %s", path);
|
|
|
|
|
|
m_mode = mode;
|
|
|
}
|
|
|
@@ -84,15 +86,15 @@ size_t OsFile::read(void* data, size_t size)
|
|
|
DWORD bytes_read;
|
|
|
|
|
|
BOOL result = ReadFile(m_file_handle, data, size, &bytes_read, NULL);
|
|
|
-
|
|
|
- CE_ASSERT(size == bytes_read, "Cannot read from file\n");
|
|
|
+
|
|
|
+ CE_ASSERT(result == TRUE, "Unable to read from file");
|
|
|
|
|
|
if (result && bytes_read == 0)
|
|
|
{
|
|
|
m_eof = true;
|
|
|
}
|
|
|
|
|
|
- return size;
|
|
|
+ return bytes_read;
|
|
|
}
|
|
|
|
|
|
size_t OsFile::write(const void* data, size_t size)
|
|
|
@@ -108,30 +110,30 @@ size_t OsFile::write(const void* data, size_t size)
|
|
|
|
|
|
void OsFile::seek(size_t position)
|
|
|
{
|
|
|
- BOOL seek_result = SetFilePointer(m_file_handle, position, NULL, FILE_BEGIN);
|
|
|
+ DWORD seek_result = SetFilePointer(m_file_handle, position, NULL, FILE_BEGIN);
|
|
|
|
|
|
- CE_ASSERT(seek_result, "Failed to seek");
|
|
|
+ CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to seek");
|
|
|
}
|
|
|
|
|
|
void OsFile::seek_to_end()
|
|
|
{
|
|
|
- BOOL seek_result = SetFilePointer(m_file_handle, 0, NULL, FILE_END);
|
|
|
+ DWORD seek_result = SetFilePointer(m_file_handle, 0, NULL, FILE_END);
|
|
|
|
|
|
- CE_ASSERT(seek_result, "Failed to seek");
|
|
|
+ CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to seek to end");
|
|
|
}
|
|
|
|
|
|
void OsFile::skip(size_t bytes)
|
|
|
{
|
|
|
- BOOL seek_result = SetFilePointer(m_file_handle, bytes, NULL, FILE_CURRENT);
|
|
|
+ DWORD seek_result = SetFilePointer(m_file_handle, bytes, NULL, FILE_CURRENT);
|
|
|
|
|
|
- CE_ASSERT(seek_result, "Failed to seek");
|
|
|
+ CE_ASSERT(seek_result != INVALID_SET_FILE_POINTER, "Failed to skip");
|
|
|
}
|
|
|
|
|
|
size_t OsFile::position() const
|
|
|
{
|
|
|
DWORD position = SetFilePointer(m_file_handle, 0, NULL, FILE_CURRENT);
|
|
|
|
|
|
- CE_ASSERT(position, "Failed to seek");
|
|
|
+ CE_ASSERT(position != INVALID_SET_FILE_POINTER, "Failed to get position");
|
|
|
|
|
|
return position;
|
|
|
}
|