removed memory_mapped_file

This commit is contained in:
rachytski 2011-10-10 15:57:47 +03:00 committed by Alex Zolotarev
parent 60d7f3919a
commit 736d608031
3 changed files with 0 additions and 89 deletions

View file

@ -16,7 +16,6 @@ SOURCES += \
string_utils.cpp \
commands_queue.cpp \
shared_buffer_manager.cpp \
memory_mapped_file.cpp \
condition.cpp \
lower_case.cpp \
normalize_unicode.cpp \
@ -62,7 +61,6 @@ HEADERS += \
commands_queue.hpp \
stats.hpp \
shared_buffer_manager.hpp \
memory_mapped_file.hpp \
buffer_vector.hpp \
array_adapters.hpp \
runner.hpp \

View file

@ -1,59 +0,0 @@
#include "memory_mapped_file.hpp"
#ifndef OMIM_OS_WINDOWS
#include <sys/mman.h>
#include <sys/errno.h>
#include <sys/stat.h>
#ifdef OMIM_OS_ANDROID
#include <fcntl.h>
#else
#include <sys/fcntl.h>
#endif
#include <unistd.h>
#endif
MemoryMappedFile::MemoryMappedFile(char const * fileName, bool isReadOnly)
: m_isReadOnly(isReadOnly)
{
#ifdef OMIM_OS_WINDOWS
m_fp = fopen(fileName, isReadOnly ? "r" : "w");
fseek(m_fp, 0, SEEK_END);
m_size = ftell(m_fp);
fseek(m_fp, 0, SEEK_SET);
m_data = reinterpret_cast<void *>(new char[m_size]);
fread(m_data, 1, m_size, m_fp);
#else
struct stat s;
stat(fileName, &s);
m_size = s.st_size;
m_fd = open(fileName, isReadOnly ? O_RDONLY : O_RDWR);
m_data = mmap(0, m_size, isReadOnly ? PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, m_fd, 0);
#endif
}
MemoryMappedFile::~MemoryMappedFile()
{
#ifdef OMIM_OS_WINDOWS
if (!m_isReadOnly)
{
fwrite(m_data, 1, m_size, m_fp);
}
fclose(m_fp);
delete[] reinterpret_cast<char *>(m_data);
#else
munmap(m_data, m_size);
close(m_fd);
#endif
}
void * MemoryMappedFile::data()
{
return m_data;
}
size_t MemoryMappedFile::size() const
{
return m_size;
}

View file

@ -1,28 +0,0 @@
#pragma once
#include "base.hpp"
#include "../std/target_os.hpp"
#include "../std/windows.hpp"
#include "../std/cstdio.hpp"
class MemoryMappedFile
{
bool m_isReadOnly;
#ifdef OMIM_OS_WINDOWS
FILE * m_fp;
#else
int m_fd;
#endif
void * m_data;
size_t m_size;
public:
MemoryMappedFile(char const * fileName, bool isReadOnly);
~MemoryMappedFile();
void * data();
size_t size() const;
};