libsqsh v1.5.1
Loading...
Searching...
No Matches
read_file_ll.c
Go to the documentation of this file.
1
9#include <sqsh.h>
10#include <stdio.h>
11
12int
13main(int argc, char *argv[]) {
14 int error_code = 0;
15 if (argc != 3) {
16 printf("Usage: %s <sqsh-file> <path>\n", argv[0]);
17 return 1;
18 }
19 struct SqshConfig config = {
20 // Read the header file to find documentation on these fields.
21 // It's safe to set them all to 0.
23 .source_size = 0,
24 .mapper_block_size = 0,
25 .mapper_lru_size = 0,
26 .metablock_lru_size = 0,
27 .data_lru_size = 0,
28 .archive_offset = 0,
29 .max_symlink_depth = 0,
30 };
31 struct SqshArchive *archive =
32 sqsh_archive_open(argv[1], &config, &error_code);
33 if (error_code != 0) {
34 sqsh_perror(error_code, "sqsh_archive_new");
35 return 1;
36 }
37 struct SqshFile *file = sqsh_open(archive, argv[2], &error_code);
38 if (error_code != 0) {
39 sqsh_perror(error_code, "sqsh_open");
40 return 1;
41 }
42
43 struct SqshFileIterator *iterator =
44 sqsh_file_iterator_new(file, &error_code);
45 if (error_code != 0) {
46 sqsh_perror(error_code, "sqsh_file_iterator_new");
47 return 1;
48 }
49
50 while (sqsh_file_iterator_next(iterator, SIZE_MAX, &error_code)) {
51 const uint8_t *data = sqsh_file_iterator_data(iterator);
52 size_t size = sqsh_file_iterator_size(iterator);
53 fwrite(data, size, 1, stdout);
54 }
55 if (error_code < 0) {
56 sqsh_perror(error_code, "sqsh_file_iterator_next");
57 return 1;
58 }
59
61 sqsh_close(file);
62 sqsh_archive_close(archive);
63 return 0;
64}
int main(int argc, char *argv[])
void sqsh_perror(int error_code, const char *msg)
Print the error message for the given error code.
const struct SqshMemoryMapperImpl *const sqsh_mapper_impl_mmap
a mapper that uses mmap to map the file into memory.
SQSH_NO_UNUSED struct SqshArchive * sqsh_archive_open(const void *source, const struct SqshConfig *config, int *err)
initializes a archive context in heap.
The SqshConfig struct contains all the configuration options for a sqsh session.
const struct SqshMemoryMapperImpl * source_mapper
source_mapper is the memory mapper implementation that will be used to map the archive.
An iterator over the contents of a file.
SQSH_NO_UNUSED size_t sqsh_file_iterator_size(const struct SqshFileIterator *iterator)
Gets the size of the data currently in the file iterator.
SQSH_NO_UNUSED struct SqshFileIterator * sqsh_file_iterator_new(const struct SqshFile *file, int *err)
Creates a new SqshFileIterator struct and initializes it.
SQSH_NO_UNUSED bool sqsh_file_iterator_next(struct SqshFileIterator *iterator, size_t desired_size, int *err)
Reads a certain amount of data from the file iterator.
int sqsh_file_iterator_free(struct SqshFileIterator *iterator)
Frees the resources used by a SqshFileIterator struct.
SQSH_NO_UNUSED const uint8_t * sqsh_file_iterator_data(const struct SqshFileIterator *iterator)
Gets a pointer to the current data in the file iterator.
The Inode context.
SQSH_NO_UNUSED struct SqshFile * sqsh_open(struct SqshArchive *archive, const char *path, int *err)
Initialize the file context from a path.