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 "MyTypes.h"
10#include "MyWindows.h"
11
12#ifdef _WIN32
13#ifdef _MSC_VER
14typedef size_t ssize_t;
15#endif
16#endif
17
18namespace NC {
19namespace NFile {
20namespace NIO {
21
22class CFileBase
23{
24protected:
25  int _handle;
26  bool OpenBinary(const char *name, int flags);
27public:
28  CFileBase(): _handle(-1) {};
29  ~CFileBase() { Close(); }
30  bool Close();
31  bool GetLength(UInt64 &length) const;
32  off_t Seek(off_t distanceToMove, int moveMethod) const;
33};
34
35class CInFile: public CFileBase
36{
37public:
38  bool Open(const char *name);
39  bool OpenShared(const char *name, bool shareForWrite);
40  ssize_t Read(void *data, size_t size);
41};
42
43class COutFile: public CFileBase
44{
45public:
46  bool Create(const char *name, bool createAlways);
47  bool Open(const char *name, DWORD creationDisposition);
48  ssize_t Write(const void *data, size_t size);
49};
50
51}}}
52
53#endif
54