diff options
Diffstat (limited to 'lib/microtar/src/microtar.h')
-rw-r--r-- | lib/microtar/src/microtar.h | 108 |
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 | ||
12 | extern "C" | ||
13 | { | ||
14 | #endif | ||
15 | |||
16 | #include <stdio.h> | ||
17 | #include <stdlib.h> | ||
18 | |||
19 | #define MTAR_VERSION "0.1.0" | ||
20 | |||
21 | enum { | ||
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 | |||
34 | enum { | ||
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 | |||
44 | typedef 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 | |||
56 | typedef 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 | |||
70 | typedef struct mtar_t mtar_t; | ||
71 | |||
72 | struct 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 | |||
86 | const char* mtar_strerror(int err); | ||
87 | |||
88 | int mtar_open(mtar_t *tar, const char *filename, const char *mode); | ||
89 | int mtar_close(mtar_t *tar); | ||
90 | |||
91 | int mtar_seek(mtar_t *tar, unsigned pos); | ||
92 | int mtar_rewind(mtar_t *tar); | ||
93 | int mtar_next(mtar_t *tar); | ||
94 | int mtar_find(mtar_t *tar, const char *name, mtar_header_t *h); | ||
95 | int mtar_read_header(mtar_t *tar, mtar_header_t *h); | ||
96 | int mtar_read_data(mtar_t *tar, void *ptr, unsigned size); | ||
97 | |||
98 | int mtar_write_header(mtar_t *tar, const mtar_header_t *h); | ||
99 | int mtar_write_file_header(mtar_t *tar, const char *name, unsigned size); | ||
100 | int mtar_write_dir_header(mtar_t *tar, const char *name); | ||
101 | int mtar_write_data(mtar_t *tar, const void *data, unsigned size); | ||
102 | int mtar_finalize(mtar_t *tar); | ||
103 | |||
104 | #ifdef __cplusplus | ||
105 | } | ||
106 | #endif | ||
107 | |||
108 | #endif | ||