#include #include // close #include // fstat #include // mmap namespace mrw { //---------------------------------------------------------------------------- AutoFile& AutoFile::reset(int fd) throw() { if (_fd!=-1) close(_fd); _fd = fd; return *this; } //---------------------------------------------------------------------------- AutoMapper::AutoMapper(int fd, size_t sz, void* addr, int prot, int flags, off_t off) throw() { if (!(_sz=sz)) { struct stat st; if (fd==-1 || fstat(fd, &st)==-1) {release(); return;} _sz = st.st_size; } if ((_cont=mmap(addr, _sz, prot, flags, fd, off))==MAP_FAILED) release(); } //---------------------------------------------------------------------------- AutoMapper::~AutoMapper() throw() { if (_cont && _sz) munmap(_cont, _sz); } }