mirror of
https://github.com/ksherlock/profuse.git
synced 2024-06-28 17:29:36 +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);
|
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()
|
File::~File()
|
||||||
{
|
{
|
||||||
close();
|
close();
|
||||||
|
|
|
@ -13,6 +13,7 @@ class File {
|
||||||
File(File &);
|
File(File &);
|
||||||
File(int fd);
|
File(int fd);
|
||||||
File(const char *name, int flags);
|
File(const char *name, int flags);
|
||||||
|
File(const char *name, bool readOnly);
|
||||||
~File();
|
~File();
|
||||||
|
|
||||||
bool isValid() const
|
bool isValid() const
|
||||||
|
|
|
@ -45,7 +45,7 @@ MappedFile::MappedFile(const char *name, bool readOnly)
|
||||||
_address = MAP_FAILED;
|
_address = MAP_FAILED;
|
||||||
_readOnly = readOnly;
|
_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"
|
#define __METHOD__ "MappedFile::init"
|
||||||
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
int prot = readOnly ? PROT_READ : PROT_READ | PROT_WRITE;
|
||||||
|
int flags = MAP_FILE | MAP_SHARED;
|
||||||
|
|
||||||
// close enough
|
// close enough
|
||||||
if (f.fd() < 0)
|
if (f.fd() < 0)
|
||||||
throw POSIXException( __METHOD__, EBADF);
|
throw POSIXException( __METHOD__, EBADF);
|
||||||
|
|
||||||
|
|
||||||
if (size <= 0)
|
if (!size)
|
||||||
{
|
{
|
||||||
if (::fstat(f.fd(), &st) != 0)
|
if (::fstat(f.fd(), &st) != 0)
|
||||||
throw POSIXException(__METHOD__ ": fstat", errno);
|
throw POSIXException(__METHOD__ ": fstat", errno);
|
||||||
|
@ -82,9 +84,7 @@ void MappedFile::init(const File &f, bool readOnly, size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
_length = size;
|
_length = size;
|
||||||
_address = ::mmap(0, _length,
|
_address = ::mmap(0, _length, prot, flags, f.fd(), 0);
|
||||||
readOnly ? PROT_READ : PROT_READ | PROT_WRITE,
|
|
||||||
MAP_FILE | MAP_SHARED, f.fd(), 0);
|
|
||||||
|
|
||||||
if (_address == MAP_FAILED)
|
if (_address == MAP_FAILED)
|
||||||
throw POSIXException(__METHOD__ ": mmap", errno);
|
throw POSIXException(__METHOD__ ": mmap", errno);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user