allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / scripts / squashfs / lzma / C / Common / C_FileIO.cpp
blob48deb70aa10ea353e94c44aee670ffc593e81c39
1 // Common/C_FileIO.h
3 #include "C_FileIO.h"
5 #include <fcntl.h>
6 #include <unistd.h>
8 namespace NC {
9 namespace NFile {
10 namespace NIO {
12 bool CFileBase::OpenBinary(const char *name, int flags)
14 #ifdef O_BINARY
15 flags |= O_BINARY;
16 #endif
17 Close();
18 _handle = ::open(name, flags, 0666);
19 return _handle != -1;
22 bool CFileBase::Close()
24 if(_handle == -1)
25 return true;
26 if (close(_handle) != 0)
27 return false;
28 _handle = -1;
29 return true;
32 bool CFileBase::GetLength(UInt64 &length) const
34 off_t curPos = Seek(0, SEEK_CUR);
35 off_t lengthTemp = Seek(0, SEEK_END);
36 Seek(curPos, SEEK_SET);
37 length = (UInt64)lengthTemp;
38 return true;
41 off_t CFileBase::Seek(off_t distanceToMove, int moveMethod) const
43 return ::lseek(_handle, distanceToMove, moveMethod);
46 /////////////////////////
47 // CInFile
49 bool CInFile::Open(const char *name)
51 return CFileBase::OpenBinary(name, O_RDONLY);
54 ssize_t CInFile::Read(void *data, size_t size)
56 return read(_handle, data, size);
59 /////////////////////////
60 // COutFile
62 bool COutFile::Create(const char *name, bool createAlways)
64 if (createAlways)
66 Close();
67 _handle = ::creat(name, 0666);
68 return _handle != -1;
70 return OpenBinary(name, O_CREAT | O_EXCL | O_WRONLY);
73 ssize_t COutFile::Write(const void *data, size_t size)
75 return write(_handle, data, size);
78 }}}