-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathread_file.c
More file actions
32 lines (27 loc) · 712 Bytes
/
read_file.c
File metadata and controls
32 lines (27 loc) · 712 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @author Enno Boland (mail@eboland.de)
* @file read_file.c
*
* This is an example program that prints the content of a file in a squashfs
* archive.
*/
#include <assert.h>
#include <sqsh.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage: %s <sqsh-file> <path>\n", argv[0]);
return 1;
}
struct SqshArchive *archive = sqsh_archive_open(argv[1], NULL, NULL);
assert(archive != NULL);
uint8_t *content = sqsh_easy_file_content(archive, argv[2], NULL);
assert(content != NULL);
size_t size = sqsh_easy_file_size2(archive, argv[2], NULL);
fwrite(content, size, 1, stdout);
free(content);
sqsh_archive_close(archive);
return 0;
}