32 #include <sys/param.h>
44 lastmap_index(size_t(-1)),
45 lastblock(nullptr), ion(-1),
117 qDebug() <<
"BlockArray::at() i > index\n";
133 if (block == (
Block*)-1) { perror(
"mmap");
return nullptr; }
145 if (res < 0) perror(
"munmap");
175 FILE* tmp = tmpfile();
177 perror(
"konsole: cannot open temp file.\n");
179 ion = dup(fileno(tmp));
181 perror(
"konsole: cannot dup temp file.\n");
195 if (newsize >
size) {
209 void moveBlock(FILE *fion,
int cursor,
int newpos,
char *buffer2)
214 res = fread(buffer2,
blocksize, 1, fion);
221 res = fwrite(buffer2,
blocksize, 1, fion);
240 FILE *fion = fdopen(dup(
ion),
"w+b");
243 perror(
"fdopen/dup");
255 for (
size_t i = 0, cursor=firstblock; i < newsize; i++) {
256 oldpos = (
size + cursor + offset) %
size;
257 moveBlock(fion, oldpos, cursor, buffer1);
258 if (oldpos < newsize) {
289 if (
size % offset == 0) {
294 FILE *fion = fdopen(dup(
ion),
"w+b");
296 perror(
"fdopen/dup");
303 for (
int i = 0; i < runs; i++)
306 int firstblock = (offset + i) %
size;
310 res = fread(buffer1,
blocksize, 1, fion);
314 for (
int j = 1, cursor=firstblock; j < bpr; j++)
316 cursor = (cursor + offset) %
size;
317 newpos = (cursor - offset +
size) %
size;
318 moveBlock(fion, cursor, newpos, buffer2);
323 res = fwrite(buffer1,
blocksize, 1, fion);
void moveBlock(FILE *fion, int cursor, int newpos, char *buffer2)
bool has(size_t index) const
void decreaseBuffer(size_t newsize)
BlockArray()
Creates a history file for holding maximal size blocks.
const Block * at(size_t index)
gets the block at the index.
Block * lastBlock() const
bool setSize(size_t newsize)
Convenient function to set the size in KBytes instead of blocks.
bool setHistorySize(size_t newsize)
reorders blocks as needed.
size_t append(Block *block)
adds the Block at the end of history.