forked from wkoszek/mini_gzip
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmini_gzip.h
More file actions
62 lines (49 loc) · 1.44 KB
/
mini_gzip.h
File metadata and controls
62 lines (49 loc) · 1.44 KB
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
52
53
54
55
56
57
58
59
60
61
62
#ifndef _MINI_GZIP_H_
#define _MINI_GZIP_H_
#include <stddef.h>
#include <stdint.h>
#define MAX_PATH_LEN 1024
#define MINI_GZ_MIN(a, b) ((a) < (b) ? (a) : (b))
struct mini_gzip {
size_t total_len;
size_t data_len;
size_t chunk_size;
uint32_t magic;
#define MINI_GZIP_MAGIC 0xbeebb00b
uint16_t fcrc;
uint16_t fextra_len;
uint8_t *hdr_ptr;
uint8_t *fextra_ptr;
uint8_t *fname_ptr;
uint8_t *fcomment_ptr;
uint8_t *data_ptr;
uint8_t pad[3];
};
/* mini_gzip.c */
extern int mini_gz_start(struct mini_gzip *gz_ptr, void *mem, size_t mem_len);
extern void mini_gz_chunksize_set(struct mini_gzip *gz_ptr, int chunk_size);
extern void mini_gz_init(struct mini_gzip *gz_ptr);
extern int mini_gz_unpack(struct mini_gzip *gz_ptr, void *mem_out, size_t mem_out_len);
#define func_fprintf fprintf
#define func_fflush fflush
#define MINI_GZ_STREAM stderr
#ifdef MINI_GZ_DEBUG
#define GZAS(comp, ...) do { \
if (!((comp))) { \
func_fprintf(MINI_GZ_STREAM, "Error: "); \
func_fprintf(MINI_GZ_STREAM, __VA_ARGS__); \
func_fprintf(MINI_GZ_STREAM, ", %s:%d\n", __func__, __LINE__); \
func_fflush(MINI_GZ_STREAM); \
exit(1); \
} \
} while (0)
#define GZDBG(...) do { \
func_fprintf(MINI_GZ_STREAM, "%s:%d ", __func__, __LINE__); \
func_fprintf(MINI_GZ_STREAM, __VA_ARGS__); \
func_fprintf(MINI_GZ_STREAM, "\n"); \
} while (0)
#else /* MINI_GZ_DEBUG */
#define GZAS(comp, ...)
#define GZDBG(...)
#endif
#endif