C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

31 lines
924 B

#include <mrw/auto.hpp>
#include <unistd.h> // close
#include <sys/stat.h> // fstat
#include <sys/mman.h> // 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);
}
}