summaryrefslogtreecommitdiff
path: root/lib/sqfs/read_table.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-07 20:19:05 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-07 20:40:07 +0200
commit60064dd0412a149fe00cfc4e2f2361c22656db57 (patch)
treef4a2aaed857aeca621ee96e46e23858d4025fcf8 /lib/sqfs/read_table.c
parente71c56420a8fc3dc7e36eb059304a362b47a1c15 (diff)
Remove printing to stderr in libsquashfs with returning error numbers
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/read_table.c')
-rw-r--r--lib/sqfs/read_table.c37
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/sqfs/read_table.c b/lib/sqfs/read_table.c
index d2664d4..843247e 100644
--- a/lib/sqfs/read_table.c
+++ b/lib/sqfs/read_table.c
@@ -8,27 +8,27 @@
#include "config.h"
#include "sqfs/meta_reader.h"
-#include "highlevel.h"
+#include "sqfs/error.h"
+#include "sqfs/table.h"
+#include "sqfs/data.h"
#include "util.h"
#include <endian.h>
#include <stdlib.h>
-#include <stdio.h>
-void *sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size,
- uint64_t location, uint64_t lower_limit,
- uint64_t upper_limit)
+int sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size,
+ uint64_t location, uint64_t lower_limit,
+ uint64_t upper_limit, void **out)
{
size_t diff, block_count, blk_idx = 0;
uint64_t start, *locations;
sqfs_meta_reader_t *m;
void *data, *ptr;
+ int err;
data = malloc(table_size);
- if (data == NULL) {
- perror("reading table");
- return NULL;
- }
+ if (data == NULL)
+ return SQFS_ERROR_ALLOC;
/* restore list from image */
block_count = table_size / SQFS_META_BLOCK_SIZE;
@@ -39,33 +39,38 @@ void *sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size,
locations = alloc_array(sizeof(uint64_t), block_count);
if (locations == NULL) {
- perror("allocation table location list");
+ err = SQFS_ERROR_ALLOC;
goto fail_data;
}
if (read_data_at("reading table locations", location,
fd, locations, sizeof(uint64_t) * block_count)) {
+ err = SQFS_ERROR_IO;
goto fail_idx;
}
/* Read the actual data */
m = sqfs_meta_reader_create(fd, cmp, lower_limit, upper_limit);
- if (m == NULL)
+ if (m == NULL) {
+ err = SQFS_ERROR_ALLOC;
goto fail_idx;
+ }
ptr = data;
while (table_size > 0) {
start = le64toh(locations[blk_idx++]);
- if (sqfs_meta_reader_seek(m, start, 0))
+ err = sqfs_meta_reader_seek(m, start, 0);
+ if (err)
goto fail;
diff = SQFS_META_BLOCK_SIZE;
if (diff > table_size)
diff = table_size;
- if (sqfs_meta_reader_read(m, ptr, diff))
+ err = sqfs_meta_reader_read(m, ptr, diff);
+ if (err)
goto fail;
ptr = (char *)ptr + diff;
@@ -74,12 +79,14 @@ void *sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size,
sqfs_meta_reader_destroy(m);
free(locations);
- return data;
+ *out = data;
+ return 0;
fail:
sqfs_meta_reader_destroy(m);
fail_idx:
free(locations);
fail_data:
free(data);
- return NULL;
+ *out = NULL;
+ return err;
}