32 #include <sys/param.h>
45 lastblock(0), ion(-1),
50 blocksize = ((
sizeof(
Block) / getpagesize()) + 1) * getpagesize();
70 rc = write(
ion, block, blocksize);
if (rc < 0) { perror(
"HistoryBuffer::add.write");
setHistorySize(0);
return size_t(-1); }
117 qDebug() <<
"BlockArray::at() i > index\n";
131 Block *block = (
Block*)mmap(0, blocksize, PROT_READ, MAP_PRIVATE,
ion, j * blocksize);
133 if (block == (
Block*)-1) { perror(
"mmap");
return 0; }
144 int res = munmap((
char*)
lastmap, blocksize);
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) {
201 if (ftruncate(
ion,
length*blocksize) == -1)
209 void moveBlock(FILE *fion,
int cursor,
int newpos,
char *buffer2)
211 int res = fseek(fion, cursor * blocksize,
SEEK_SET);
214 res = fread(buffer2, blocksize, 1, fion);
218 res = fseek(fion, newpos * blocksize,
SEEK_SET);
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;
307 res = fseek(fion, firstblock * blocksize,
SEEK_SET);
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);
320 res = fseek(fion, i * blocksize,
SEEK_SET);
323 res = fwrite(buffer1, blocksize, 1, fion);