22 Private() : addr(MAP_FAILED)
32 int fd = open(filename, O_RDONLY);
38 d->addr = mmap(0, d->size, PROT_READ, MAP_PRIVATE | MAP_POPULATE, fd, 0);
39 if (d->addr == MAP_FAILED)
41 d->addr = mmap(0, d->size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
42 if (d->addr != MAP_FAILED)
44 read(fd, d->addr, d->size);
53 if (d->addr != MAP_FAILED)
55 munmap(d->addr, d->size);
62 return d->addr != MAP_FAILED;
67 return (
const unsigned char*) d->addr;
89 d->fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0644);
114 ftruncate(d->fd, maxSize);
115 d->mapSize = maxSize;
116 void* addr = mmap(0, d->mapSize, PROT_WRITE | PROT_READ, MAP_SHARED, d->fd, 0);
117 if (addr != MAP_FAILED)
119 return (
unsigned char*) addr;
123 return (
unsigned char*) malloc(maxSize);
134 munmap(data, d->mapSize);
135 ftruncate(d->fd, size);
139 write(d->fd, data, size);
145 #else // defined(HAVE_MMAP) 164 FILE *fp = fopen(filename,
"rb");
167 fseek(fp, 0, SEEK_END);
169 fseek(fp, 0, SEEK_SET);
171 d->buffer = (
unsigned char *) malloc(d->size);
173 d->size = fread(d->buffer, 1, d->size, fp);
180 InputFile::~InputFile()
188 bool InputFile::isReadable()
const 190 return d->buffer != 0;
193 const unsigned char *InputFile::data()
const 198 size_t InputFile::dataSize()
const 212 OutputFile::OutputFile(
const char *filename)
215 d->fp = fopen(filename,
"wb");
221 OutputFile::~OutputFile()
229 bool OutputFile::isWritable()
const 237 unsigned char *OutputFile::prepareData(
size_t maxSize)
239 return (
unsigned char *) malloc(maxSize);
242 void OutputFile::commitData(
unsigned char *data,
size_t size)
246 fwrite(data, 1, size, d->fp);
252 #endif // defined(HAVE_MMAP)
OutputFile(const char *filename)
void commitData(unsigned char *data, size_t size)
unsigned char * prepareData(size_t maxSize)