mirror of
https://github.com/ksherlock/profuse.git
synced 2025-04-01 17:30:20 +00:00
git-svn-id: https://profuse.googlecode.com/svn/branches/v2@224 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
77fda944ae
commit
e53674e015
@ -36,6 +36,18 @@ File::File(const char *name, int flags)
|
||||
throw POSIXException( __METHOD__ ": open", errno);
|
||||
}
|
||||
|
||||
|
||||
File::File(const char *name, bool readOnly)
|
||||
{
|
||||
#undef __METHOD__
|
||||
#define __METHOD__ "File::File"
|
||||
|
||||
_fd = ::open(name, readOnly ? O_RDONLY : O_RDWR);
|
||||
if (_fd < 0)
|
||||
throw POSIXException( __METHOD__ ": open", errno);
|
||||
}
|
||||
|
||||
|
||||
File::~File()
|
||||
{
|
||||
close();
|
||||
|
@ -13,6 +13,7 @@ class File {
|
||||
File(File &);
|
||||
File(int fd);
|
||||
File(const char *name, int flags);
|
||||
File(const char *name, bool readOnly);
|
||||
~File();
|
||||
|
||||
bool isValid() const
|
||||
|
@ -45,7 +45,7 @@ MappedFile::MappedFile(const char *name, bool readOnly)
|
||||
_address = MAP_FAILED;
|
||||
_readOnly = readOnly;
|
||||
|
||||
init(f, readOnly, -1);
|
||||
init(f, readOnly, 0);
|
||||
|
||||
}
|
||||
|
||||
@ -64,13 +64,15 @@ void MappedFile::init(const File &f, bool readOnly, size_t size)
|
||||
#define __METHOD__ "MappedFile::init"
|
||||
|
||||
struct stat st;
|
||||
int prot = readOnly ? PROT_READ : PROT_READ | PROT_WRITE;
|
||||
int flags = MAP_FILE | MAP_SHARED;
|
||||
|
||||
// close enough
|
||||
if (f.fd() < 0)
|
||||
throw POSIXException( __METHOD__, EBADF);
|
||||
|
||||
|
||||
if (size <= 0)
|
||||
if (!size)
|
||||
{
|
||||
if (::fstat(f.fd(), &st) != 0)
|
||||
throw POSIXException(__METHOD__ ": fstat", errno);
|
||||
@ -82,9 +84,7 @@ void MappedFile::init(const File &f, bool readOnly, size_t size)
|
||||
}
|
||||
|
||||
_length = size;
|
||||
_address = ::mmap(0, _length,
|
||||
readOnly ? PROT_READ : PROT_READ | PROT_WRITE,
|
||||
MAP_FILE | MAP_SHARED, f.fd(), 0);
|
||||
_address = ::mmap(0, _length, prot, flags, f.fd(), 0);
|
||||
|
||||
if (_address == MAP_FAILED)
|
||||
throw POSIXException(__METHOD__ ": mmap", errno);
|
||||
|
Loading…
x
Reference in New Issue
Block a user