aboutsummaryrefslogtreecommitdiffstats
path: root/lib/util.c
blob: e80954b3de9db508ddde5bc25e87376c501dee76 (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

#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_basedir_exist(const char *storage) {
    char *_storage = strdup(storage);
    char *basedir = dirname(_storage);
    free(_storage);

    struct stat d;
    if (stat(basedir, &d) != 0 || !S_ISDIR(d.st_mode)) {
        return -1;
    }
    return 0;
}

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 {
        fprintf(stderr, "Unknown compression algorithm: %s\n", flag);
        return 0;
    }
}