libsqsh v1.5.1
Loading...
Searching...
No Matches
readme_example.c
Go to the documentation of this file.
1
6#include <assert.h>
7#include <sqsh.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11int
12main(int argc, char *argv[]) {
13 (void)argc;
14 (void)argv;
15
16 struct SqshArchive *archive =
17 sqsh_archive_open("/path/to/archive.squashfs", NULL, NULL);
18 assert(archive != NULL);
19
20 uint8_t *contents = sqsh_easy_file_content(archive, "/path/to/file", NULL);
21 assert(contents != NULL);
22 const size_t size = sqsh_easy_file_size2(archive, "/path/to/file", NULL);
23 fwrite(contents, 1, size, stdout);
24 free(contents);
25
26 char **files = sqsh_easy_directory_list(archive, "/path/to/dir", NULL);
27 assert(files != NULL);
28 for (int i = 0; files[i] != NULL; i++) {
29 puts(files[i]);
30 }
31 free(files);
32
33 sqsh_archive_close(archive);
34 return 0;
35}
int main(int argc, char *argv[])
uint64_t sqsh_easy_file_size2(struct SqshArchive *archive, const char *path, int *err)
retrieves the size of a file.
char ** sqsh_easy_directory_list(struct SqshArchive *archive, const char *path, int *err)
retrieves the contents of a directory as a list of file names
uint8_t * sqsh_easy_file_content(struct SqshArchive *archive, const char *path, int *err)
retrieves the content of a file.
SQSH_NO_UNUSED struct SqshArchive * sqsh_archive_open(const void *source, const struct SqshConfig *config, int *err)
initializes a archive context in heap.
int sqsh_archive_close(struct SqshArchive *archive)
Frees the resources used by a Sqsh instance.