summaryrefslogtreecommitdiff
path: root/src/file.c
diff options
context:
space:
mode:
authorjakob <jakob@memeware.net>2017-01-17 15:29:07 -0500
committerjakob <jakob@memeware.net>2017-01-17 15:29:07 -0500
commit6d844032442f36b924e1c270a123dc970ddd96a6 (patch)
tree14ae61f8a0efc0b0e3de7462b9b4dc5a5e9f83eb /src/file.c
parentef05e4e0b8c5cc21b57ae60b60cfbfc7f046bd59 (diff)
Improved readability.
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/file.c b/src/file.c
index 3274859..d2a9b72 100644
--- a/src/file.c
+++ b/src/file.c
@@ -35,7 +35,9 @@ void read_segm_chunk(memory_stream *data_stream, file_node *parsed,
uint64_t segment_count);
-/* Creates a file node by parsing a file entry. */
+/* Creates a node for a File entry, which can be deferred in a linked
+ list. NULL will be returned if there isn't enough memory to contain
+ the node structure. */
file_node *read_file_entry(memory_stream *data_stream, Bytef *section_end) {
uint32_t entry_magic;
uint64_t entry_size;
@@ -50,9 +52,11 @@ file_node *read_file_entry(memory_stream *data_stream, Bytef *section_end) {
read_adlr_chunk(data_stream, parsed);
break;
case SEGM_MAGIC:
- /* Segments are 28 bytes each. */
+ /* The segment count is not included in the table and
+ has to be calculated. Segments are 28 bytes each. */
read_segm_chunk(data_stream, parsed, entry_size / 28);
- /* Check if segments was successfully allocated. */
+ /* There can't really be a check for this
+ in read_segm_chunk, so it's done here. */
if (parsed->segments == NULL) {
free(parsed);
return NULL;
@@ -72,7 +76,7 @@ file_node *read_file_entry(memory_stream *data_stream, Bytef *section_end) {
}
-/* Reads the contents of an info chunk int a file_node. */
+/* Reads the contents of an info chunk into a file node. */
void read_info_chunk(memory_stream *data_stream, file_node *parsed) {
uint32_t encrypted;
uint64_t decompressed_size, compressed_size;
@@ -89,13 +93,14 @@ void read_info_chunk(memory_stream *data_stream, file_node *parsed) {
}
-/* Reads the contents of a segm chunk into a file_node. */
+/* Reads the contents of a segm chunk into a file node. */
void read_segm_chunk(memory_stream *data_stream, file_node *parsed,
uint64_t segment_count) {
/* Segments are stored in an array of segment pointers. */
segment **segments = malloc(sizeof(segment *) * segment_count);
if (segments == NULL)
return;
+
for (uint64_t i = 0; i < segment_count; i++) {
segments[i] = malloc(sizeof(segment));
read_stream(&segments[i]->compressed,