-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
mkpdx.c
51 lines (48 loc) · 1 KB
/
mkpdx.c
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
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
void write_big_uint32(FILE *f, uint32_t i) {
uint8_t buf[4] = {
i >> 24,
(i >> 16) & 0xff,
(i >> 8) & 0xff,
i & 0xff
};
fwrite(buf, 1, 4, f);
}
int main(int argc, char **argv) {
int ofs = 96 * 8;
for(int i = 1; i <= 96; i++) {
int size = 0;
if(i < argc) {
struct stat st;
int r = stat(argv[i], &st);
if(r < 0) {
fprintf(stderr, "Could not stat %s: %s (%d)\n", argv[i], strerror(errno), errno);
continue;
}
size = st.st_size;
}
write_big_uint32(stdout, ofs);
write_big_uint32(stdout, size);
ofs += size;
}
for(int i = 1; i < argc; i++) {
FILE *f = fopen(argv[i], "rb");
if(!f) {
fprintf(stderr, "Could not open %s: %s (%d)\n", argv[i], strerror(errno), errno);
continue;
}
uint8_t buf[1024];
while(!feof(f)) {
int r = fread(buf, 1, sizeof(buf), f);
fwrite(buf, 1, r, stdout);
}
fclose(f);
}
return 0;
}