-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilefunc.c
More file actions
32 lines (27 loc) · 801 Bytes
/
filefunc.c
File metadata and controls
32 lines (27 loc) · 801 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
size_t filelength = 0;
int loadinputfile(unsigned char *inbuf, char *filename)
{
FILE *in;
in = fopen(filename, "rb");
if (in == NULL) {
fprintf(stderr, "error: could not open '%s' for reading.\n", filename);
exit(-1);
}
filelength = fread(inbuf, 1, MAXFILELENGTH, in);
fclose(in);
addrlines = getnumbits(filelength-1);
if ((1 << addrlines) != filelength) {
fprintf(stderr, "error: input file length should be a power of two.\n");
}
}
int saveoutputfile(unsigned char *outbuf, char *filename)
{
FILE *out;
out = fopen(outfilename, "wb");
if (out == NULL) {
fprintf(stderr, "error: could not open '%s' for writing.\n", outfilename);
exit(-1);
}
fwrite(outbuf, 1, filelength, out);
fclose(out);
}