#include "Common/compat-c.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <stdint.h>
#include <stdarg.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "bmz-internal.h"
Go to the source code of this file.
|
#define | BMZ_MAGIC "BMZ" |
|
#define | BMZIP_VER 0x0110 |
|
#define | BMZ_HEADER_SZ (3 + 2 + 1 + 6 + 4) |
|
#define | BMZ_A_PACK 0 |
|
#define | BMZ_A_UNPACK 1 |
|
#define | BMZ_A_LIST 2 |
|
#define | BMZ_O_BM_ONLY 1 |
|
#define | BMZ_O_STREAM 2 /* TODO */ |
|
#define | LOG(_lvl_, _fmt_,...) |
|
#define | WARN(_fmt_,...) |
|
#define | DIE(_fmt_,...) |
|
#define | BMZ_ALIGN(_mem_, _n_) (Byte *)(_mem_) + _n_ - (((size_t)(_mem_))%(_n_)) |
|
#define | BMZ_READ_INT16(_p_, _n_) |
|
#define | BMZ_READ_INT32(_p_, _n_) |
|
#define | BMZ_READ_INT48(_p_, _n_) |
|
#define | BMZ_WRITE_INT16(_p_, _n_) |
|
#define | BMZ_WRITE_INT32(_p_, _n_) |
|
#define | BMZ_WRITE_INT48(_p_, _n_) |
|
|
typedef unsigned char | Byte |
|
typedef long long unsigned | Llu |
|
typedef long unsigned | Lu |
|
|
static void | read_bmz_header (int fd, Byte *buf) |
|
static void | parse_bmz_header (const Byte *buf, uint16_t *version_p, uint64_t *orig_size_p, uint32_t *checksum_p, uint32_t *options) |
|
static void | write_bmz_header (int fd, size_t in_len, uint32_t checksum, Byte options) |
|
static void | do_list (int fd) |
|
static void | do_pack (const void *in, size_t in_len, size_t buf_len, size_t offset, size_t fp_len, Byte options) |
|
static void | do_unpack (const void *in, size_t in_len, size_t buf_len) |
|
static void | do_block (const void *in, size_t len, size_t buf_len, size_t offset, size_t fp_len, int action, int options) |
|
static char * | read_from_fp (FILE *fp, size_t *len_p, size_t *size_p) |
|
static char * | read_from_fd (int fd, size_t *len_p, size_t *size_p) |
|
static void | input_from_stdin (size_t offset, size_t fp_len, int action, int options) |
|
static void | input_from_file (const char *fname, size_t offset, size_t fp_len, int action, int options) |
|
static int | bm_hash (const char *name) |
|
static void HT_NORETURN | show_usage () |
|
int | main (int ac, char *av[]) |
|
#define BMZ_ALIGN |
( |
|
_mem_, |
|
|
|
_n_ |
|
) |
| (Byte *)(_mem_) + _n_ - (((size_t)(_mem_))%(_n_)) |
#define BMZ_HEADER_SZ (3 + 2 + 1 + 6 + 4) |
#define BMZ_O_STREAM 2 /* TODO */ |
#define BMZ_READ_INT16 |
( |
|
_p_, |
|
|
|
_n_ |
|
) |
| |
Value:_n_ = (*_p_++ << 8); \
_n_ |= (*_p_++)
Definition at line 85 of file bmzip.c.
#define BMZ_READ_INT32 |
( |
|
_p_, |
|
|
|
_n_ |
|
) |
| |
Value:_n_ = (*_p_++ << 24); \
_n_ |= (*_p_++ << 16); \
_n_ |= (*_p_++ << 8); \
_n_ |= (*_p_++)
Definition at line 89 of file bmzip.c.
#define BMZ_READ_INT48 |
( |
|
_p_, |
|
|
|
_n_ |
|
) |
| |
Value:_n_ = ((uint64_t)*_p_++ << 40); \
_n_ |= ((uint64_t)*_p_++ << 32); \
_n_ |= (*_p_++ << 24); \
_n_ |= (*_p_++ << 16); \
_n_ |= (*_p_++ << 8); \
_n_ |= (*_p_++)
Definition at line 95 of file bmzip.c.
#define BMZ_WRITE_INT16 |
( |
|
_p_, |
|
|
|
_n_ |
|
) |
| |
Value:*_p_++ = (
Byte)(_n_ >> 8); \
Definition at line 103 of file bmzip.c.
#define BMZ_WRITE_INT32 |
( |
|
_p_, |
|
|
|
_n_ |
|
) |
| |
Value:*_p_++ = (
Byte)(_n_ >> 24); \
*_p_++ = (
Byte)(_n_ >> 16); \
*_p_++ = (
Byte)(_n_ >> 8); \
Definition at line 107 of file bmzip.c.
#define BMZ_WRITE_INT48 |
( |
|
_p_, |
|
|
|
_n_ |
|
) |
| |
Value:*_p_++ = (
Byte)(_n_ >> 40); \
*_p_++ = (
Byte)(_n_ >> 32); \
*_p_++ = (
Byte)(_n_ >> 24); \
*_p_++ = (
Byte)(_n_ >> 16); \
*_p_++ = (
Byte)(_n_ >> 8); \
Definition at line 113 of file bmzip.c.
#define DIE |
( |
|
_fmt_, |
|
|
|
... |
|
) |
| |
Value:
LOG(0,
"fatal: " _fmt_, ##__VA_ARGS__); \
exit(1); \
} while (0)
#define LOG(_lvl_, _fmt_,...)
Definition at line 78 of file bmzip.c.
#define LOG |
( |
|
_lvl_, |
|
|
|
_fmt_, |
|
|
|
... |
|
) |
| |
Value:
fprintf(stderr, "bmzip: %s: " _fmt_, __FUNCTION__, ##__VA_ARGS__); \
if (errno) fprintf(stderr, ": %s", strerror(errno)); \
putc('\n', stderr); \
} while (0)
Definition at line 68 of file bmzip.c.
#define WARN |
( |
|
_fmt_, |
|
|
|
... |
|
) |
| |
Value:
LOG(0,
"warning: " _fmt_, ##__VA_ARGS__); \
} while (0)
#define LOG(_lvl_, _fmt_,...)
Definition at line 74 of file bmzip.c.
typedef unsigned char Byte |
typedef long long unsigned Llu |
static int bm_hash |
( |
const char * |
name | ) |
|
|
static |
static void do_block |
( |
const void * |
in, |
|
|
size_t |
len, |
|
|
size_t |
buf_len, |
|
|
size_t |
offset, |
|
|
size_t |
fp_len, |
|
|
int |
action, |
|
|
int |
options |
|
) |
| |
|
static |
static void do_list |
( |
int |
fd | ) |
|
|
static |
static void do_pack |
( |
const void * |
in, |
|
|
size_t |
in_len, |
|
|
size_t |
buf_len, |
|
|
size_t |
offset, |
|
|
size_t |
fp_len, |
|
|
Byte |
options |
|
) |
| |
|
static |
static void do_unpack |
( |
const void * |
in, |
|
|
size_t |
in_len, |
|
|
size_t |
buf_len |
|
) |
| |
|
static |
static void input_from_file |
( |
const char * |
fname, |
|
|
size_t |
offset, |
|
|
size_t |
fp_len, |
|
|
int |
action, |
|
|
int |
options |
|
) |
| |
|
static |
static void input_from_stdin |
( |
size_t |
offset, |
|
|
size_t |
fp_len, |
|
|
int |
action, |
|
|
int |
options |
|
) |
| |
|
static |
int main |
( |
int |
ac, |
|
|
char * |
av[] |
|
) |
| |
static void parse_bmz_header |
( |
const Byte * |
buf, |
|
|
uint16_t * |
version_p, |
|
|
uint64_t * |
orig_size_p, |
|
|
uint32_t * |
checksum_p, |
|
|
uint32_t * |
options |
|
) |
| |
|
static |
static void read_bmz_header |
( |
int |
fd, |
|
|
Byte * |
buf |
|
) |
| |
|
static |
static char* read_from_fd |
( |
int |
fd, |
|
|
size_t * |
len_p, |
|
|
size_t * |
size_p |
|
) |
| |
|
static |
static char* read_from_fp |
( |
FILE * |
fp, |
|
|
size_t * |
len_p, |
|
|
size_t * |
size_p |
|
) |
| |
|
static |
static void write_bmz_header |
( |
int |
fd, |
|
|
size_t |
in_len, |
|
|
uint32_t |
checksum, |
|
|
Byte |
options |
|
) |
| |
|
static |
Copyright (C) 2007-2015 Hypertable, Inc.
This file is part of Hypertable.
Hypertable is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 3 of the License, or any later version.
Hypertable is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Hypertable. If not, see http://www.gnu.org/licenses/A demo app for bmz compression
Definition at line 35 of file bmzip.c.