Fixed various errors based on differences between new version and original code.

This commit is contained in:
2026-05-04 21:49:37 +02:00
parent e6bda0c239
commit 5f667b2b16
12 changed files with 13082 additions and 46 deletions
+30 -1
View File
@@ -27,10 +27,22 @@
#include "BlockArray.h"
// System
#include <sys/mman.h>
#if !defined(Q_OS_WIN)
# include <sys/mman.h>
#endif
#include <sys/param.h>
#include <unistd.h>
#include <cstdio>
#include <cstdlib>
#if defined(Q_OS_WIN)
# include <windows.h>
static int getpagesize() {
SYSTEM_INFO si;
GetSystemInfo(&si);
return static_cast<int>(si.dwPageSize);
}
#endif
using namespace Konsole;
@@ -151,12 +163,25 @@ const Block * BlockArray::at(size_t i)
Q_ASSERT(j < size);
unmap();
#if defined(Q_OS_WIN)
Block * block = static_cast<Block *>(malloc(blocksize));
if (!block) {
perror("malloc");
return nullptr;
}
lseek(ion, static_cast<off_t>(j) * blocksize, SEEK_SET);
if (read(ion, block, blocksize) < 0) {
free(block);
return nullptr;
}
#else
Block * block = (Block *)mmap(nullptr, blocksize, PROT_READ, MAP_PRIVATE, ion, j * blocksize);
if (block == (Block *)-1) {
perror("mmap");
return nullptr;
}
#endif
lastmap = block;
lastmap_index = i;
@@ -167,10 +192,14 @@ const Block * BlockArray::at(size_t i)
void BlockArray::unmap()
{
if (lastmap) {
#if defined(Q_OS_WIN)
free(lastmap);
#else
int res = munmap((char *)lastmap, blocksize);
if (res < 0) {
perror("munmap");
}
#endif
}
lastmap = nullptr;
lastmap_index = size_t(-1);