summaryrefslogtreecommitdiff
path: root/util/arid.cpp
blob: ab2bccb60d304623657d5423d0d709f3697a9438 (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
#include <iostream>
#include "minimal/mapping.h"

struct ar_hdr {
    char ar_name[16];
    char ar_date[12];
    char ar_uid[6];
    char ar_gid[6];
    char ar_mode[8];
    char ar_size[10];
#define	ARFMAG "`\n"
    char ar_fmag[2];
};

int main(int argc, char *argv[]) {
    size_t size;
    _assert(argc == 2);
    uint8_t *data = reinterpret_cast<uint8_t *>(map(argv[1], 0, _not(size_t), &size, false));
    data += 8;
    uint8_t *end = data + size;
    while (end - data >= sizeof(struct ar_hdr)) {
        struct ar_hdr *head = reinterpret_cast<struct ar_hdr *>(data);
        memset(head->ar_date + 1, ' ', sizeof(head->ar_date) - 1);
        head->ar_date[0] = '0';
        size_t length = strtoul(head->ar_size, NULL, 10);
        data += length + sizeof(struct ar_hdr);
    }
    return 0;
}