Example #1
0
    MMap::~MMap()
    {
      if (!first) return;
      if (addr) {
        DEBUG ("unmapping file \"" + Entry::name + "\"");
#ifdef MRTRIX_WINDOWS
        if (!UnmapViewOfFile ( (LPVOID) addr))
#else
          if (munmap (addr, msize))
#endif
            WARN ("error unmapping file \"" + Entry::name + "\": " + strerror (errno));
        close (fd);
      }
      else {
        if (readwrite) {
          INFO ("writing back contents of mapped file \"" + Entry::name + "\"...");
          File::OFStream out (Entry::name, std::ios::in | std::ios::out | std::ios::binary);
          out.seekp (start, out.beg);
          out.write ((char*) first, msize);
          if (!out.good())
            throw Exception ("error writing back contents of file \"" + Entry::name + "\": " + strerror(errno));
        }
        delete [] first;
      }
    }
Example #2
0
    void Default::unload (const Header& header)
    {
      if (mmaps.empty() && addresses.size()) {
        assert (addresses[0].get());

        if (writable) {
          for (size_t n = 0; n < files.size(); n++) {
            File::OFStream out (files[n].name, std::ios::out | std::ios::binary);
            out.seekp (files[n].start, out.beg);
            out.write ((char*) (addresses[0].get() + n*bytes_per_segment), bytes_per_segment);
            if (!out.good())
              throw Exception ("error writing back contents of file \"" + files[n].name + "\": " + strerror(errno));
          }
        }
      }
      else {
        for (size_t n = 0; n < addresses.size(); ++n)
          addresses[n].release();
        mmaps.clear();
      }
    }