]> git.saurik.com Git - ldid.git/blob - arid.cpp
Support read-only mmap when possible.
[ldid.git] / arid.cpp
1 #include <iostream>
2 #include <string.h>
3 #include "minimal/mapping.h"
4
5 struct ar_hdr {
6 char ar_name[16];
7 char ar_date[12];
8 char ar_uid[6];
9 char ar_gid[6];
10 char ar_mode[8];
11 char ar_size[10];
12 #define ARFMAG "`\n"
13 char ar_fmag[2];
14 };
15
16 int main(int argc, char *argv[]) {
17 size_t size;
18 _assert(argc == 2);
19 uint8_t *data = reinterpret_cast<uint8_t *>(map(argv[1], 0, _not(size_t), &size, false));
20 data += 8;
21 uint8_t *end = data + size;
22 while (end - data >= sizeof(struct ar_hdr)) {
23 struct ar_hdr *head = reinterpret_cast<struct ar_hdr *>(data);
24 memset(head->ar_date + 1, ' ', sizeof(head->ar_date) - 1);
25 head->ar_date[0] = '0';
26 size_t length = strtoul(head->ar_size, NULL, 10);
27 data += length + sizeof(struct ar_hdr);
28 }
29 return 0;
30 }