Skip to content

Commit

Permalink
Have Linux resize files to the appropiate size
Browse files Browse the repository at this point in the history
  • Loading branch information
knivey committed Mar 24, 2016
1 parent ffa8828 commit 15bab6f
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions everdb-native/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,8 @@ int hash_map(hash *db, uint64_t size) {
if (db == NULL) return -1;
int ret = 0;

#ifdef _WIN32

hash_map_close(db);

#ifdef _WIN32
db->h_mapping = CreateFileMapping(
db->h_file,
NULL,
Expand All @@ -179,9 +177,19 @@ int hash_map(hash *db, uint64_t size) {
ret = -9;
goto err;
}
db->size = size;

#elif __linux__
if (db->size < size) {
if (fallocate(db->h_file, 0, 0, size) < 0) {
ret = -11;
goto err;
}
}
if (db->size > size) {
if (ftruncate(db->h_file, size) < 0) {
ret = -12;
goto err;
}
}
db->data = mmap(
NULL,
size,
Expand All @@ -196,6 +204,7 @@ int hash_map(hash *db, uint64_t size) {
goto err;
}
#endif
db->size = size;

return ret;

Expand Down

0 comments on commit 15bab6f

Please sign in to comment.