Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
4,010 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
_codelite/ | ||
PPMVC/ | ||
|
||
# Archives | ||
*.zip | ||
|
||
# Object files | ||
*.o | ||
*.ko | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
// FileStreams.cpp | ||
|
||
#include "StdAfx.h" | ||
|
||
#ifndef _WIN32 | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <errno.h> | ||
#endif | ||
|
||
#include "FileStreams.h" | ||
|
||
static inline HRESULT ConvertBoolToHRESULT(bool result) | ||
{ | ||
// return result ? S_OK: E_FAIL; | ||
#ifdef _WIN32 | ||
return result ? S_OK: (::GetLastError()); | ||
#else | ||
return result ? S_OK: E_FAIL; | ||
#endif | ||
} | ||
|
||
bool CInFileStream::Open(LPCTSTR fileName) | ||
{ | ||
return File.Open(fileName); | ||
} | ||
|
||
#ifdef _WIN32 | ||
#ifndef _UNICODE | ||
bool CInFileStream::Open(LPCWSTR fileName) | ||
{ | ||
return File.Open(fileName); | ||
} | ||
#endif | ||
#endif | ||
|
||
STDMETHODIMP CInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize) | ||
{ | ||
#ifdef _WIN32 | ||
|
||
UInt32 realProcessedSize; | ||
bool result = File.ReadPart(data, size, realProcessedSize); | ||
if(processedSize != NULL) | ||
*processedSize = realProcessedSize; | ||
return ConvertBoolToHRESULT(result); | ||
|
||
#else | ||
|
||
if(processedSize != NULL) | ||
*processedSize = 0; | ||
ssize_t res = File.Read(data, (size_t)size); | ||
if (res == -1) | ||
return E_FAIL; | ||
if(processedSize != NULL) | ||
*processedSize = (UInt32)res; | ||
return S_OK; | ||
|
||
#endif | ||
} | ||
|
||
#ifndef _WIN32_WCE | ||
STDMETHODIMP CStdInFileStream::Read(void *data, UInt32 size, UInt32 *processedSize) | ||
{ | ||
#ifdef _WIN32 | ||
UInt32 realProcessedSize; | ||
BOOL res = ::ReadFile(GetStdHandle(STD_INPUT_HANDLE), | ||
data, size, (DWORD *)&realProcessedSize, NULL); | ||
if(processedSize != NULL) | ||
*processedSize = realProcessedSize; | ||
if (res == FALSE && GetLastError() == ERROR_BROKEN_PIPE) | ||
return S_OK; | ||
return ConvertBoolToHRESULT(res != FALSE); | ||
|
||
#else | ||
|
||
if(processedSize != NULL) | ||
*processedSize = 0; | ||
ssize_t res; | ||
do | ||
{ | ||
res = read(0, data, (size_t)size); | ||
} | ||
while (res < 0 && (errno == EINTR)); | ||
if (res == -1) | ||
return E_FAIL; | ||
if(processedSize != NULL) | ||
*processedSize = (UInt32)res; | ||
return S_OK; | ||
|
||
#endif | ||
} | ||
|
||
#endif | ||
|
||
STDMETHODIMP CInFileStream::Seek(Int64 offset, UInt32 seekOrigin, | ||
UInt64 *newPosition) | ||
{ | ||
if(seekOrigin >= 3) | ||
return STG_E_INVALIDFUNCTION; | ||
|
||
#ifdef _WIN32 | ||
|
||
UInt64 realNewPosition; | ||
bool result = File.Seek(offset, seekOrigin, realNewPosition); | ||
if(newPosition != NULL) | ||
*newPosition = realNewPosition; | ||
return ConvertBoolToHRESULT(result); | ||
|
||
#else | ||
|
||
off_t res = File.Seek(offset, seekOrigin); | ||
if (res == -1) | ||
return E_FAIL; | ||
if(newPosition != NULL) | ||
*newPosition = (UInt64)res; | ||
return S_OK; | ||
|
||
#endif | ||
} | ||
|
||
STDMETHODIMP CInFileStream::GetSize(UInt64 *size) | ||
{ | ||
return ConvertBoolToHRESULT(File.GetLength(*size)); | ||
} | ||
|
||
|
||
////////////////////////// | ||
// COutFileStream | ||
|
||
bool COutFileStream::Create(LPCTSTR fileName, bool createAlways) | ||
{ | ||
return File.Create(fileName, createAlways); | ||
} | ||
|
||
#ifdef _WIN32 | ||
#ifndef _UNICODE | ||
bool COutFileStream::Create(LPCWSTR fileName, bool createAlways) | ||
{ | ||
return File.Create(fileName, createAlways); | ||
} | ||
#endif | ||
#endif | ||
|
||
STDMETHODIMP COutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize) | ||
{ | ||
#ifdef _WIN32 | ||
|
||
UInt32 realProcessedSize; | ||
bool result = File.WritePart(data, size, realProcessedSize); | ||
if(processedSize != NULL) | ||
*processedSize = realProcessedSize; | ||
return ConvertBoolToHRESULT(result); | ||
|
||
#else | ||
|
||
if(processedSize != NULL) | ||
*processedSize = 0; | ||
ssize_t res = File.Write(data, (size_t)size); | ||
if (res == -1) | ||
return E_FAIL; | ||
if(processedSize != NULL) | ||
*processedSize = (UInt32)res; | ||
return S_OK; | ||
|
||
#endif | ||
} | ||
|
||
STDMETHODIMP COutFileStream::Seek(Int64 offset, UInt32 seekOrigin, | ||
UInt64 *newPosition) | ||
{ | ||
if(seekOrigin >= 3) | ||
return STG_E_INVALIDFUNCTION; | ||
#ifdef _WIN32 | ||
|
||
UInt64 realNewPosition; | ||
bool result = File.Seek(offset, seekOrigin, realNewPosition); | ||
if(newPosition != NULL) | ||
*newPosition = realNewPosition; | ||
return ConvertBoolToHRESULT(result); | ||
|
||
#else | ||
|
||
off_t res = File.Seek(offset, seekOrigin); | ||
if (res == -1) | ||
return E_FAIL; | ||
if(newPosition != NULL) | ||
*newPosition = (UInt64)res; | ||
return S_OK; | ||
|
||
#endif | ||
} | ||
|
||
STDMETHODIMP COutFileStream::SetSize(Int64 newSize) | ||
{ | ||
#ifdef _WIN32 | ||
UInt64 currentPos; | ||
if(!File.Seek(0, FILE_CURRENT, currentPos)) | ||
return E_FAIL; | ||
bool result = File.SetLength(newSize); | ||
UInt64 currentPos2; | ||
result = result && File.Seek(currentPos, currentPos2); | ||
return result ? S_OK : E_FAIL; | ||
#else | ||
return E_FAIL; | ||
#endif | ||
} | ||
|
||
#ifndef _WIN32_WCE | ||
STDMETHODIMP CStdOutFileStream::Write(const void *data, UInt32 size, UInt32 *processedSize) | ||
{ | ||
if(processedSize != NULL) | ||
*processedSize = 0; | ||
|
||
#ifdef _WIN32 | ||
UInt32 realProcessedSize; | ||
BOOL res = TRUE; | ||
if (size > 0) | ||
{ | ||
// Seems that Windows doesn't like big amounts writing to stdout. | ||
// So we limit portions by 32KB. | ||
UInt32 sizeTemp = (1 << 15); | ||
if (sizeTemp > size) | ||
sizeTemp = size; | ||
res = ::WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), | ||
data, sizeTemp, (DWORD *)&realProcessedSize, NULL); | ||
size -= realProcessedSize; | ||
data = (const void *)((const Byte *)data + realProcessedSize); | ||
if(processedSize != NULL) | ||
*processedSize += realProcessedSize; | ||
} | ||
return ConvertBoolToHRESULT(res != FALSE); | ||
|
||
#else | ||
|
||
ssize_t res; | ||
do | ||
{ | ||
res = write(1, data, (size_t)size); | ||
} | ||
while (res < 0 && (errno == EINTR)); | ||
if (res == -1) | ||
return E_FAIL; | ||
if(processedSize != NULL) | ||
*processedSize = (UInt32)res; | ||
return S_OK; | ||
|
||
return S_OK; | ||
#endif | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// FileStreams.h | ||
|
||
#ifndef __FILESTREAMS_H | ||
#define __FILESTREAMS_H | ||
|
||
#ifdef _WIN32 | ||
#include "../../Windows/FileIO.h" | ||
#else | ||
#include "../../Common/C_FileIO.h" | ||
#endif | ||
|
||
#include "../IStream.h" | ||
#include "../../Common/MyCom.h" | ||
|
||
class CInFileStream: | ||
public IInStream, | ||
public IStreamGetSize, | ||
public CMyUnknownImp | ||
{ | ||
public: | ||
#ifdef _WIN32 | ||
NWindows::NFile::NIO::CInFile File; | ||
#else | ||
NC::NFile::NIO::CInFile File; | ||
#endif | ||
CInFileStream() {} | ||
virtual ~CInFileStream() {} | ||
|
||
bool Open(LPCTSTR fileName); | ||
#ifdef _WIN32 | ||
#ifndef _UNICODE | ||
bool Open(LPCWSTR fileName); | ||
#endif | ||
#endif | ||
|
||
MY_UNKNOWN_IMP2(IInStream, IStreamGetSize) | ||
|
||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); | ||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); | ||
|
||
STDMETHOD(GetSize)(UInt64 *size); | ||
}; | ||
|
||
#ifndef _WIN32_WCE | ||
class CStdInFileStream: | ||
public ISequentialInStream, | ||
public CMyUnknownImp | ||
{ | ||
public: | ||
// HANDLE File; | ||
// CStdInFileStream() File(INVALID_HANDLE_VALUE): {} | ||
// void Open() { File = GetStdHandle(STD_INPUT_HANDLE); }; | ||
MY_UNKNOWN_IMP | ||
|
||
virtual ~CStdInFileStream() {} | ||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); | ||
}; | ||
#endif | ||
|
||
class COutFileStream: | ||
public IOutStream, | ||
public CMyUnknownImp | ||
{ | ||
public: | ||
#ifdef _WIN32 | ||
NWindows::NFile::NIO::COutFile File; | ||
#else | ||
NC::NFile::NIO::COutFile File; | ||
#endif | ||
virtual ~COutFileStream() {} | ||
bool Create(LPCTSTR fileName, bool createAlways); | ||
#ifdef _WIN32 | ||
#ifndef _UNICODE | ||
bool Create(LPCWSTR fileName, bool createAlways); | ||
#endif | ||
#endif | ||
|
||
MY_UNKNOWN_IMP1(IOutStream) | ||
|
||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); | ||
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition); | ||
STDMETHOD(SetSize)(Int64 newSize); | ||
}; | ||
|
||
#ifndef _WIN32_WCE | ||
class CStdOutFileStream: | ||
public ISequentialOutStream, | ||
public CMyUnknownImp | ||
{ | ||
public: | ||
MY_UNKNOWN_IMP | ||
|
||
virtual ~CStdOutFileStream() {} | ||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); | ||
}; | ||
#endif | ||
|
||
#endif |
Oops, something went wrong.