Esempio n. 1
0
void FileBinaryStream::Open(boost::filesystem::path const& rFilePath)
{
  m_FileName = rFilePath;
  m_FileHandle = open(rFilePath.string().c_str(), O_RDONLY);

  if (m_FileHandle == -1)
    throw Exception_System("open");

  struct stat sb;

  m_MapHandle = NULL;

  if (fstat(m_FileHandle, &sb) == -1)
    throw Exception_System("fstat");

  m_Size = sb.st_size;

  m_pBuffer = mmap(
      NULL,
      m_Size,
      PROT_READ,
      MAP_SHARED,
      m_FileHandle,
      0);

  if (m_pBuffer == MAP_FAILED)
    throw Exception_System("mmap");
}
Esempio n. 2
0
  FuncType Load(boost::filesystem::path const& ModulePath, std::string const& FunctionName)
  {
    void* pModule = ImplLoadLibrary(ModulePath);
    if (pModule == nullptr)
      throw Exception_System("LoadLibraryW/dlopen");

    return reinterpret_cast<FuncType>(ImplGetFunctionAddress(pModule, FunctionName));
  }
Esempio n. 3
0
void MemoryBinaryStream::Open(void const* pMem, u32 MemSize)
{
  m_pBuffer = ::malloc(MemSize);
  if (m_pBuffer == nullptr)
    throw Exception_System("open");

  m_Size    = MemSize;
  ::memcpy(m_pBuffer, pMem, MemSize);
}
Esempio n. 4
0
void FileBinaryStream::Open(std::wstring const& rFilePath)
{
  m_FileName = rFilePath;

  char *pUtf8FileName = new char[rFilePath.length() + 1];
  if (wcstombs(pUtf8FileName, rFilePath.c_str(), rFilePath.length()) == -1)
  {
    delete [] pUtf8FileName;
    throw Exception_System(L"wcstombs");
  }

  pUtf8FileName[rFilePath.length()] = '\0';

  m_FileHandle = open(pUtf8FileName, O_RDONLY);

  delete [] pUtf8FileName;
  pUtf8FileName = nullptr;

  if (m_FileHandle == -1)
    throw Exception_System(L"open");

  struct stat sb;

  m_MapHandle = NULL;

  if (fstat(m_FileHandle, &sb) == -1)
    throw Exception_System(L"fstat");

  m_Size = sb.st_size;

  m_pBuffer = mmap(
      NULL,
      m_Size,
      PROT_READ,
      MAP_SHARED,
      m_FileHandle,
      0);

  if (m_pBuffer == MAP_FAILED)
    throw Exception_System(L"mmap");
}