Skip to content

Instantly share code, notes, and snippets.

@poppycocker
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poppycocker/9500621 to your computer and use it in GitHub Desktop.
Save poppycocker/9500621 to your computer and use it in GitHub Desktop.
StdioFile64
#include "StdAfx.h"
class CStdioFile64 : public CStdioFile
{
public:
CStdioFile64(LPCTSTR lpszFileName, UINT nOpenFlags) : CStdioFile(lpszFileName, nOpenFlags){}
virtual ~CStdioFile64(){};
ULONGLONG Seek(LONGLONG lOff, UINT nFrom);
ULONGLONG GetLength() const;
ULONGLONG GetPosition() const;
};
ULONGLONG CStdioFile64::Seek(LONGLONG lOff, UINT nFrom)
{
ASSERT_VALID(this);
ASSERT(nFrom == begin || nFrom == end || nFrom == current);
ASSERT(m_pStream != NULL);
if (_fseeki64(m_pStream, lOff, nFrom) != 0)
AfxThrowFileException(CFileException::badSeek, _doserrno,
m_strFileName);
return _ftelli64(m_pStream);
}
ULONGLONG CStdioFile64::GetLength() const
{
ASSERT_VALID(this);
LONGLONG nCurrent, nLength;
int nResult;
nCurrent = _ftelli64(m_pStream);
if (nCurrent == -1)
AfxThrowFileException(CFileException::invalidFile, _doserrno, m_strFileName);
nResult = _fseeki64(m_pStream, 0, SEEK_END);
if (nResult != 0)
AfxThrowFileException(CFileException::badSeek, _doserrno, m_strFileName);
nLength = _ftelli64(m_pStream);
if (nLength == -1)
AfxThrowFileException(CFileException::invalidFile, _doserrno, m_strFileName);
nResult = _fseeki64(m_pStream, nCurrent, SEEK_SET);
if (nResult != 0)
AfxThrowFileException(CFileException::badSeek, _doserrno, m_strFileName);
return nLength;
}
ULONGLONG CStdioFile64::GetPosition() const
{
ASSERT_VALID(this);
ASSERT(m_pStream != NULL);
LONGLONG pos = _ftelli64(m_pStream);
if (pos == -1)
AfxThrowFileException(CFileException::invalidFile, _doserrno, m_strFileName);
return pos;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment