-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31a6b37
commit 0646a7b
Showing
3 changed files
with
70 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "reader.h" | ||
|
||
// todo return errors instead of exiting | ||
|
||
Reader *newReader(const char *filename) { | ||
Reader *reader = malloc(sizeof(Reader)); | ||
if (reader == NULL) { | ||
fprintf(stderr, "Could not allocate memory for reader"); | ||
exit(EXIT_FAILURE); | ||
} | ||
reader->fp = fopen(filename, "rb"); | ||
if (reader->fp == NULL) { | ||
fprintf(stderr, "Could not open file"); | ||
free(reader); | ||
exit(EXIT_FAILURE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef HADRON_READER_H | ||
#define HADRON_READER_H | ||
|
||
#define CHUNK_SIZE 1024 | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <malloc.h> | ||
|
||
typedef struct Reader { | ||
FILE *fp; | ||
char buffer[CHUNK_SIZE]; | ||
size_t buffer_size; | ||
size_t buffer_pos; | ||
} Reader; | ||
|
||
Reader *newReader(const char *filename); | ||
void freeReader(Reader *reader); | ||
size_t readChunk(Reader *reader); | ||
|
||
#endif |