blob: 5a9076f5f3b739b3610bf57b0e29716ce203be83 (
plain) (
blame)
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
|
#include "main.h"
#include <libgen.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
int check_file_exist(const char *storage) {
return access(storage, F_OK) != -1;
}
int check_file_size(const char *storage) {
struct stat st;
stat(storage, &st);
return st.st_size;
}
int check_basedir_exist(const char *storage) {
char *_storage = strdup(storage);
char *basedir = dirname(_storage);
struct stat d; int ret = 0;
if (stat(basedir, &d) != 0 || !S_ISDIR(d.st_mode))
ret = -1;
free(_storage);
return ret;
}
enum CompressionType get_compression(const char *flag) {
if (flag == NULL) {
return COMPRESS_NONE;
} else if (!strcmp(flag, "zstd") || !strcmp(flag, "zstandard")) {
return COMPRESS_ZSTD;
} else if (!strcmp(flag, "lz4")) {
return COMPRESS_LZ4;
} else {
FATAL("Unknown compression algorithm: %s\n", flag);
exit(1);
}
return 0;
}
|