|
|
// File64.h: interface for the CFile64 class.
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
//主要功能:
|
|
|
// 超长文件操作类
|
|
|
//
|
|
|
//程序编写: 2008-11-09
|
|
|
//
|
|
|
//
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
#include <sys/stat.h>
|
|
|
#include <io.h>
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//将一个64位整数转换为指定radix(10进制、16进制、2进制)的字符串
|
|
|
void Integer64ToString( __int64 value, char *string, int radix );
|
|
|
__int64 StringToInteger64( const char *string ); //将一字符串转换为64位整数
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
#if !defined(AFX_FILE64_H__48BF1FE7_1799_4B95_A4AE_A9BDD4D5C2E6__INCLUDED_)
|
|
|
#define AFX_FILE64_H__48BF1FE7_1799_4B95_A4AE_A9BDD4D5C2E6__INCLUDED_
|
|
|
|
|
|
#if _MSC_VER > 1000
|
|
|
#pragma once
|
|
|
#endif // _MSC_VER > 1000
|
|
|
/*
|
|
|
class CFile64 : public CFile
|
|
|
{
|
|
|
public:
|
|
|
CFile64();
|
|
|
virtual ~CFile64();
|
|
|
|
|
|
virtual BOOL Open(LPCTSTR lpszFileName); //以只读二进制方式打开文件
|
|
|
BOOL OpenWrite(LPCTSTR lpszFileName,BOOL bTruncate=FALSE); //以写方式打开文件
|
|
|
BOOL OpenAppend(LPCTSTR lpszFileName); //以追加写方式打开文件
|
|
|
|
|
|
virtual BOOL IsOpen(void);
|
|
|
};*/
|
|
|
|
|
|
namespace NFile64
|
|
|
{
|
|
|
|
|
|
class CFile64
|
|
|
{
|
|
|
public:
|
|
|
CFile64(LPCTSTR lpszFileName, int oflag=_O_BINARY|_O_RDONLY, int pmode=_S_IREAD);
|
|
|
CFile64();
|
|
|
virtual ~CFile64();
|
|
|
|
|
|
public:
|
|
|
virtual BOOL Open(LPCTSTR lpszFileName); //以只读二进制方式打开文件
|
|
|
virtual UINT Read( void *lpBuf, UINT count); //到文件结尾返回0,读错误返回-1
|
|
|
virtual void Write(const void *lpBuf, UINT count);
|
|
|
virtual BOOL IsOpen(void);
|
|
|
virtual BOOL IsEof();
|
|
|
virtual void Close();
|
|
|
|
|
|
//开头 SEEK_SET, 结尾 SEEK_END, 当前 SEEK_CUR;
|
|
|
virtual __int64 Seek(__int64 offset, int origin); //失败返回-1
|
|
|
|
|
|
__int64 SeekToEnd();
|
|
|
void SeekToBegin();
|
|
|
void Flush();
|
|
|
|
|
|
__int64 GetStat( struct _stati64 *buffer ); //成功返回0,失败返回-1
|
|
|
__int64 GetLength(); //成功返回文件长度,失败返回-1
|
|
|
__int64 GetPosition(); //失败返回-1,当设备无64位寻址能力时返回值不确定
|
|
|
int GetHandle(void); //获得文件句柄
|
|
|
|
|
|
//打开文件成功返回TRUE,错误返回FALSE
|
|
|
BOOL Open( LPCTSTR lpszFileName, int oflag, int pmode );
|
|
|
BOOL Open( LPCTSTR lpszFileName, int oflag );
|
|
|
//以“_O_BINARY|_O_CREAT|_O_WRONLY|_O_TRUNC, _S_IWRITE”方式打开文件
|
|
|
BOOL OpenWrite(LPCTSTR lpszFileName,BOOL bTruncate=FALSE);
|
|
|
BOOL OpenAppend(LPCTSTR lpszFileName);//以追加写方式打开文件
|
|
|
|
|
|
protected:
|
|
|
int m_hFile;
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
using namespace NFile64;
|
|
|
|
|
|
inline BOOL CFile64::IsOpen(void)
|
|
|
{
|
|
|
if(m_hFile==-1) return 0;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
inline int CFile64::GetHandle(void)
|
|
|
{
|
|
|
return m_hFile;
|
|
|
}
|
|
|
|
|
|
#endif // !defined(AFX_FILE64_H__48BF1FE7_1799_4B95_A4AE_A9BDD4D5C2E6__INCLUDED_)
|