aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorYunchih Chen <yunchih.cat@gmail.com>2018-03-18 21:10:49 +0800
committerYunchih Chen <yunchih.cat@gmail.com>2018-03-18 21:10:49 +0800
commitd6fe4152d0a213cc64336853271188371c9d3563 (patch)
tree9a69e6900bb96a9e2906c14840968a92c9eab159 /lib
parent597453d4b147cb0e07704e1dec455cfc7cebe382 (diff)
downloadnfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.gz
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.bz2
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.lz
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.xz
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.tar.zst
nfcollect-d6fe4152d0a213cc64336853271188371c9d3563.zip
Format with clang-format
Diffstat (limited to 'lib')
-rw-r--r--lib/commit.c35
-rw-r--r--lib/extract.c58
2 files changed, 51 insertions, 42 deletions
diff --git a/lib/commit.c b/lib/commit.c
index ca90598..f2fbc06 100644
--- a/lib/commit.c
+++ b/lib/commit.c
@@ -8,7 +8,8 @@ static void nfl_commit_default(FILE *f, nfl_entry_t *store,
static void nfl_commit_lz4(FILE *f, nfl_entry_t *store, uint32_t store_size);
static void nfl_commit_zstd(FILE *f, nfl_entry_t *store, uint32_t store_size);
-void nfl_commit_init() { /* TODO */ }
+void nfl_commit_init() { /* TODO */
+}
static void nfl_commit_default(FILE *f, nfl_entry_t *store,
uint32_t store_size) {
@@ -21,8 +22,7 @@ static void nfl_commit_lz4(FILE *f, nfl_entry_t *store, uint32_t store_size) {
/* TODO */
}
-static void nfl_commit_zstd(FILE *f, nfl_entry_t *store,
- uint32_t store_size) {
+static void nfl_commit_zstd(FILE *f, nfl_entry_t *store, uint32_t store_size) {
size_t const bufsize = ZSTD_compressBound(store_size);
void *buf;
@@ -50,21 +50,22 @@ void nfl_commit_worker(nfl_header_t *header, nfl_entry_t *store,
// commit store
uint32_t store_size = sizeof(nfl_entry_t) * header->max_n_entries;
- switch(compression_opt) {
- case COMPRESS_NONE:
- debug("Comm worker #%u: commit without compression\n", header->id)
+ switch (compression_opt) {
+ case COMPRESS_NONE:
+ debug("Comm worker #%u: commit without compression\n", header->id)
nfl_commit_default(f, store, store_size);
- break;
- case COMPRESS_LZ4:
- debug("Comm worker #%u: commit with compression algorithm: lz4", header->id)
- nfl_commit_lz4(f, store, store_size);
- break;
- case COMPRESS_ZSTD:
- debug("Comm worker #%u: commit with compression algorithm: zstd", header->id)
- nfl_commit_zstd(f, store, store_size);
- break;
- // Must not reach here ...
- default: FATAL("Unknown compression option detected");
+ break;
+ case COMPRESS_LZ4:
+ debug("Comm worker #%u: commit with compression algorithm: lz4",
+ header->id) nfl_commit_lz4(f, store, store_size);
+ break;
+ case COMPRESS_ZSTD:
+ debug("Comm worker #%u: commit with compression algorithm: zstd",
+ header->id) nfl_commit_zstd(f, store, store_size);
+ break;
+ // Must not reach here ...
+ default:
+ FATAL("Unknown compression option detected");
}
// Do fsync ?
diff --git a/lib/extract.c b/lib/extract.c
index 61bf340..822c216 100644
--- a/lib/extract.c
+++ b/lib/extract.c
@@ -11,7 +11,7 @@ static int nfl_extract_zstd(FILE *f, nfl_state_t *state);
static int nfl_extract_lz4(FILE *f, nfl_state_t *state);
static int nfl_verify_header(nfl_header_t *header) {
- if(header->cksum != nfl_header_cksum(header))
+ if (header->cksum != nfl_header_cksum(header))
return -1;
if (header->id > MAX_TRUNK_ID)
@@ -37,24 +37,28 @@ static int nfl_extract_default(FILE *f, nfl_state_t *state) {
static int nfl_extract_zstd(FILE *f, nfl_state_t *state) {
char *buf;
size_t const compressed_size = nfl_get_filesize(f) - sizeof(nfl_header_t),
- expected_decom_size = state->header->n_entries * sizeof(nfl_entry_t);
+ expected_decom_size =
+ state->header->n_entries * sizeof(nfl_entry_t);
ERR(!(buf = malloc(compressed_size)), "zstd: cannot malloc");
fread(buf, compressed_size, 1, f);
WARN_RETURN(ferror(f), "%s", strerror(errno));
- size_t const estimate_decom_size = ZSTD_findDecompressedSize(buf, compressed_size);
+ size_t const estimate_decom_size =
+ ZSTD_findDecompressedSize(buf, compressed_size);
if (estimate_decom_size == ZSTD_CONTENTSIZE_ERROR)
FATAL("zstd: file was not compressed by zstd.\n");
else if (estimate_decom_size == ZSTD_CONTENTSIZE_UNKNOWN)
- FATAL("zstd: original size unknown. Use streaming decompression instead");
+ FATAL(
+ "zstd: original size unknown. Use streaming decompression instead");
- size_t const actual_decom_size =
- ZSTD_decompress(state->store, expected_decom_size, buf, compressed_size);
+ size_t const actual_decom_size = ZSTD_decompress(
+ state->store, expected_decom_size, buf, compressed_size);
if (actual_decom_size != expected_decom_size) {
- FATAL("zstd: error decoding current file: %s \n", ZSTD_getErrorName(actual_decom_size));
- }
+ FATAL("zstd: error decoding current file: %s \n",
+ ZSTD_getErrorName(actual_decom_size));
+ }
free(buf);
return 0;
@@ -75,31 +79,35 @@ int nfl_extract_worker(const char *filename, nfl_state_t *state) {
/* ERR(nfl_check_file(f) < 0, "extract worker"); */
// Read header
- ERR(!(state->header = malloc(sizeof(nfl_header_t))), "extract malloc header");
+ ERR(!(state->header = malloc(sizeof(nfl_header_t))),
+ "extract malloc header");
got = fread(state->header, sizeof(nfl_header_t), 1, f);
h = state->header;
// Check header validity
WARN_RETURN(ferror(f), "%s", strerror(errno));
- WARN_RETURN(!got || nfl_verify_header(h) < 0, "File %s has corrupted header.", filename);
+ WARN_RETURN(!got || nfl_verify_header(h) < 0,
+ "File %s has corrupted header.", filename);
// Read body
- ERR(!(state->store = malloc(sizeof(nfl_entry_t) * h->n_entries)), "extract malloc store");
- switch(h->compression_opt) {
- case COMPRESS_NONE:
- debug("Extract worker #%u: extract without compression\n", h->id)
+ ERR(!(state->store = malloc(sizeof(nfl_entry_t) * h->n_entries)),
+ "extract malloc store");
+ switch (h->compression_opt) {
+ case COMPRESS_NONE:
+ debug("Extract worker #%u: extract without compression\n", h->id)
nfl_extract_default(f, state);
- break;
- case COMPRESS_LZ4:
- debug("Extract worker #%u: extract with compression algorithm: lz4", h->id)
- nfl_extract_lz4(f, state);
- break;
- case COMPRESS_ZSTD:
- debug("Extract worker #%u: extract with compression algorithm: zstd", h->id)
- nfl_extract_zstd(f, state);
- break;
- // Must not reach here ...
- default: FATAL("Unknown compression option detected");
+ break;
+ case COMPRESS_LZ4:
+ debug("Extract worker #%u: extract with compression algorithm: lz4",
+ h->id) nfl_extract_lz4(f, state);
+ break;
+ case COMPRESS_ZSTD:
+ debug("Extract worker #%u: extract with compression algorithm: zstd",
+ h->id) nfl_extract_zstd(f, state);
+ break;
+ // Must not reach here ...
+ default:
+ FATAL("Unknown compression option detected");
}
fclose(f);