C_FileIO.h revision baa3858d3f5d128a5c8466b700098109edcad5f2
1// Common/C_FileIO.h 2 3#ifndef __COMMON_C_FILEIO_H 4#define __COMMON_C_FILEIO_H 5 6#include <stdio.h> 7#include <sys/types.h> 8 9#include "Types.h" 10#include "MyWindows.h" 11 12namespace NC { 13namespace NFile { 14namespace NIO { 15 16class CFileBase 17{ 18protected: 19 int _handle; 20 bool OpenBinary(const char *name, int flags); 21public: 22 CFileBase(): _handle(-1) {}; 23 ~CFileBase() { Close(); } 24 bool Close(); 25 bool GetLength(UInt64 &length) const; 26 off_t Seek(off_t distanceToMove, int moveMethod) const; 27}; 28 29class CInFile: public CFileBase 30{ 31public: 32 bool Open(const char *name); 33 bool OpenShared(const char *name, bool shareForWrite); 34 ssize_t Read(void *data, size_t size); 35}; 36 37class COutFile: public CFileBase 38{ 39public: 40 bool Create(const char *name, bool createAlways); 41 bool Open(const char *name, DWORD creationDisposition); 42 ssize_t Write(const void *data, size_t size); 43}; 44 45}}} 46 47#endif 48