summaryrefslogtreecommitdiff
path: root/lib/microtar/src/microtar.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/microtar/src/microtar.h')
-rw-r--r--lib/microtar/src/microtar.h108
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/microtar/src/microtar.h b/lib/microtar/src/microtar.h
new file mode 100644
index 0000000000..d30c829521
--- /dev/null
+++ b/lib/microtar/src/microtar.h
@@ -0,0 +1,108 @@
1/**
2 * Copyright (c) 2017 rxi
3 *
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the MIT license. See `microtar.c` for details.
6 */
7
8#ifndef MICROTAR_H
9#define MICROTAR_H
10
11#ifdef __cplusplus
12extern "C"
13{
14#endif
15
16#include <stdio.h>
17#include <stdlib.h>
18
19#define MTAR_VERSION "0.1.0"
20
21enum {
22 MTAR_ESUCCESS = 0,
23 MTAR_EFAILURE = -1,
24 MTAR_EOPENFAIL = -2,
25 MTAR_EREADFAIL = -3,
26 MTAR_EWRITEFAIL = -4,
27 MTAR_ESEEKFAIL = -5,
28 MTAR_EBADCHKSUM = -6,
29 MTAR_ENULLRECORD = -7,
30 MTAR_ENOTFOUND = -8,
31 MTAR_EOVERFLOW = -9,
32};
33
34enum {
35 MTAR_TREG = '0',
36 MTAR_TLNK = '1',
37 MTAR_TSYM = '2',
38 MTAR_TCHR = '3',
39 MTAR_TBLK = '4',
40 MTAR_TDIR = '5',
41 MTAR_TFIFO = '6'
42};
43
44typedef struct {
45 unsigned mode;
46 unsigned owner;
47 unsigned group;
48 unsigned size;
49 unsigned mtime;
50 unsigned type;
51 char name[101]; /* +1 byte in order to ensure null termination */
52 char linkname[101];
53} mtar_header_t;
54
55
56typedef struct {
57 char name[100];
58 char mode[8];
59 char owner[8];
60 char group[8];
61 char size[12];
62 char mtime[12];
63 char checksum[8];
64 char type;
65 char linkname[100];
66 char _padding[255];
67} mtar_raw_header_t;
68
69
70typedef struct mtar_t mtar_t;
71
72struct mtar_t {
73 int (*read)(mtar_t *tar, void *data, unsigned size);
74 int (*write)(mtar_t *tar, const void *data, unsigned size);
75 int (*seek)(mtar_t *tar, unsigned pos);
76 int (*close)(mtar_t *tar);
77 void *stream;
78 unsigned pos;
79 unsigned remaining_data;
80 unsigned last_header;
81 mtar_header_t header;
82 mtar_raw_header_t raw_header;
83};
84
85
86const char* mtar_strerror(int err);
87
88int mtar_open(mtar_t *tar, const char *filename, const char *mode);
89int mtar_close(mtar_t *tar);
90
91int mtar_seek(mtar_t *tar, unsigned pos);
92int mtar_rewind(mtar_t *tar);
93int mtar_next(mtar_t *tar);
94int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h);
95int mtar_read_header(mtar_t *tar, mtar_header_t *h);
96int mtar_read_data(mtar_t *tar, void *ptr, unsigned size);
97
98int mtar_write_header(mtar_t *tar, const mtar_header_t *h);
99int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size);
100int mtar_write_dir_header(mtar_t *tar, const char *name);
101int mtar_write_data(mtar_t *tar, const void *data, unsigned size);
102int mtar_finalize(mtar_t *tar);
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif