-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlight_io_zlib.c
56 lines (46 loc) · 1.24 KB
/
light_io_zlib.c
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
// Copyright (c) 2021 Technica Engineering GmbH
// This code is licensed under MIT license (see LICENSE for details)
#ifdef LIGHT_USE_ZLIB
#include "light_io.h"
#include "light_io_internal.h"
#include "light_io_zlib.h"
#include <stdlib.h>
#include <stdio.h>
#include <zlib.h> // presumes zlib library is installed
size_t light_zlib_read(void* context, void* buf, size_t count)
{
return gzread((gzFile)context, buf, count);
}
size_t light_zlib_write(void* context, const void* buf, size_t count)
{
return gzwrite((gzFile)context, buf, count);
}
int light_zlib_flush(void* context)
{
return gzflush((gzFile)context, Z_NO_FLUSH);
}
int light_zlib_seek(void* context, long int offset, int origin)
{
return gzseek((gzFile)context, offset, origin);
}
int light_zlib_close(void* context)
{
return gzclose((gzFile)context);
}
light_file light_io_zlib_open(const char* filename, const char* mode)
{
gzFile file = gzopen(filename, mode);
if (!file)
{
return NULL;
}
light_file fd = malloc(sizeof(struct light_file_t));
fd->context = file;
fd->fn_read = &light_zlib_read;
fd->fn_write = &light_zlib_write;
fd->fn_flush = &light_zlib_flush;
fd->fn_seek = &light_zlib_seek;
fd->fn_close = &light_zlib_close;
return fd;
}
#endif // LIGHT_USE_zlib