forked from ovh/ovh-ttyrec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compress.c
61 lines (48 loc) · 1.27 KB
/
compress.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
57
58
59
60
61
// vim: noai:ts=4:sw=4:expandtab:
/* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
* Copyright 2019 The ovh-ttyrec Authors. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "compress.h"
#include "configure.h"
#ifdef HAVE_zstd
# include "compress_zstd.h"
#endif
size_t (*fread_wrapper)(void *ptr, size_t size, size_t nmemb, FILE *stream) = fread;
size_t (*fwrite_wrapper)(const void *ptr, size_t size, size_t nmemb, FILE *stream) = fwrite;
int (*fclose_wrapper)(FILE *fp) = fclose;
static long compress_level = -1;
int set_compress_mode(compress_mode_t cm)
{
switch (cm)
{
case COMPRESS_NONE:
fread_wrapper = fread;
fwrite_wrapper = fwrite;
fclose_wrapper = fclose;
break;
#ifdef HAVE_zstd
case COMPRESS_ZSTD:
fread_wrapper = fread_wrapper_zstd;
fwrite_wrapper = fwrite_wrapper_zstd;
fclose_wrapper = fclose_wrapper_zstd;
break;
#endif
default:
fprintf(stderr, "ttyrec: unsupported compression mode\r\n");
return 1;
}
return 0;
}
void set_compress_level(long level)
{
compress_level = level;
}
long get_compress_level(void)
{
return compress_level;
}