Skip to content
Snippets Groups Projects
Commit bce6f1f9 authored by Florian Burgener's avatar Florian Burgener
Browse files

Missing fopen

parent 2aff5a47
Branches
No related tags found
No related merge requests found
......@@ -63,6 +63,8 @@ static void rebuild_index(Directory *directory) {
break;
}
}
fclose(fp);
}
Directory *Directory_init(char database_filename[100]) {
......@@ -111,6 +113,7 @@ void Directory_print(Directory *directory) {
}
printf("========================\n");
fclose(fp);
}
bool Directory_append(Directory *directory, DirectoryRecord *record) {
......@@ -131,7 +134,7 @@ bool Directory_append(Directory *directory, DirectoryRecord *record) {
fwrite(byte_array->items, 1, byte_array->size, fp);
ByteArray_destroy(&byte_array);
uint64_t data_ptr = (uint64_t)ftell(fp) - 55;
uint64_t data_ptr = (uint64_t)ftell(fp) - DirectoryRecord_size_on_disk();
fclose(fp);
bptree_insert(directory->index, hash_string(record->phone_number), data_ptr);
......@@ -152,6 +155,8 @@ DirectoryRecord *Directory_search(Directory *directory, char phone_number[11]) {
ByteArray *byte_array = ByteArray_init(DirectoryRecord_size_on_disk());
fread(byte_array->items, 1, DirectoryRecord_size_on_disk(), fp);
byte_array->size = DirectoryRecord_size_on_disk();
fclose(fp);
DirectoryRecord *record = ByteArray_to_DirectoryRecord(byte_array);
ByteArray_destroy(&byte_array);
return record;
......
......@@ -49,15 +49,15 @@ ByteArray *DirectoryRecord_to_ByteArray(DirectoryRecord *record) {
ByteArray *array = ByteArray_init(capacity);
ByteArray_append(array, (uint8_t)record->deleted);
for (int j = 0; j < PHONE_NUMBER_MAX_LENGTH - 1; j++) {
for (int j = 0; j < PHONE_NUMBER_MAX_LENGTH_WITHOUT_NULL_CHARACTER; j++) {
ByteArray_append(array, (uint8_t)record->phone_number[j]);
}
for (int j = 0; j < NAME_MAX_LENGTH - 1; j++) {
for (int j = 0; j < NAME_MAX_LENGTH_WITHOUT_NULL_CHARACTER; j++) {
ByteArray_append(array, (uint8_t)record->name[j]);
}
for (int j = 0; j < SURNAME_MAX_LENGTH - 1; j++) {
for (int j = 0; j < SURNAME_MAX_LENGTH_WITHOUT_NULL_CHARACTER; j++) {
ByteArray_append(array, (uint8_t)record->surname[j]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment