#include "filewrapper.hh"
#include "error.hh"


filewrapper::filewrapper (const std::string& name)
{
  const char* name_c = name.c_str ();
  if ((fd = open (name_c, O_RDONLY)) == -1) {
    perror ("open");
    error ("cannot open input file", name);
  }

  struct stat stat_buf;
  if (stat (name_c, &stat_buf) == -1) {
    perror ("stat");
    error ("cannot stat file", name);
  }
  file_size = stat_buf.st_size;

  ;
  if ( (memblock = (const unsigned char*) mmap (NULL, file_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) {
    perror ("mmap");
    error ("could not mmap file", name);
  }
}


int64_t filewrapper::size ()
{
  return file_size;
}


