split_buffer

This commit is contained in:
bronku 2025-10-24 22:35:14 +02:00
parent f31bf4712c
commit 758f733c84
2 changed files with 15 additions and 5 deletions

View file

@ -22,10 +22,21 @@ void destroy_buffer(buffer* buff)
free(buff);
}
// #todo
buffer* split_buffer(buffer* original, int pieces)
buffer** split_buffer(buffer* original, int pieces)
{
return NULL;
int size = original->capacity;
if (size <= 0) {
return NULL;
}
buffer** out = malloc(sizeof(buffer) * pieces);
for (int i = 0; i < pieces; i++) {
out[i]->length = 0;
out[i]->capacity = size;
out[i]->original = 0;
out[i]->location = original->location;
out[i]->location += i * size * sizeof(record);
}
return out;
}
int read_buffer(buffer* buff, FILE* in)

View file

@ -9,10 +9,9 @@ typedef struct {
bool original;
} buffer;
// #todo switch to returning a pointer, and write destroy_buffer method
buffer* create_buffer(int capacity);
void destroy_buffer(buffer* buff);
buffer* split_buffer(buffer* original, int pieces);
buffer** split_buffer(buffer* original, int pieces);
int read_buffer(buffer* buff, FILE* in);
int write_buffer(buffer* buff, FILE* in);