blob: a5f79e7e043d460bbe30b618f7c3a91e73865e15 (
plain)
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
33
34
35
36
37
38
39
40
41
42
|
#include "cccl.h"
#include <assert.h>
#include <err.h>
#include <stdio.h>
int main(int argc, char **argv)
{
if (!argv[1])
return 1;
struct cccl_File file;
int error = cccl_allocfile(argv[1], &file);
if (error)
err(1, "cccl_readfile()");
FILE *f = fopen(argv[1], "r");
if (!f)
err(1, "fopen()");
int bytes_read = 0;
while (bytes_read < file.size)
{
int read_now = fread(
file.buffer + bytes_read,
sizeof(*file.buffer),
(file.size - bytes_read) % 2048,
f
);
if (read_now == 0)
{
if (ferror(f))
errx(1, "couldn't read %s", argv[1]);
else
break;
}
}
fclose(f);
cccl(file);
}
|