refactor
This commit is contained in:
parent
7c888a3dd0
commit
5d9fc7d18d
11 changed files with 247 additions and 297 deletions
43
buffer.c
Normal file
43
buffer.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "buffer.h"
|
||||
#include "record.h"
|
||||
#include "status_codes.h"
|
||||
|
||||
buffer create_buffer(int capacity)
|
||||
{
|
||||
buffer out;
|
||||
out.length = 0;
|
||||
out.capacity = capacity;
|
||||
out.location = malloc(sizeof(record) * capacity);
|
||||
return out;
|
||||
}
|
||||
|
||||
int read_buffer(buffer* buff, FILE* in)
|
||||
{
|
||||
int status;
|
||||
record* current = buff->location;
|
||||
buff->length = 0;
|
||||
for (int i = 0; i < buff->capacity; i++) {
|
||||
status = read_record(in, current);
|
||||
if (status != SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
buff->length++;
|
||||
current++;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int write_buffer(buffer* buff, FILE* out)
|
||||
{
|
||||
int status;
|
||||
record* current = buff->location;
|
||||
for (int i = 0; i < buff->length; i++) {
|
||||
status = print_record(out, current);
|
||||
if (status < 0) {
|
||||
return status;
|
||||
}
|
||||
fprintf(out, "\n");
|
||||
current++;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue