bmzip.c File Reference

#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"

Include dependency graph for bmzip.c:

Go to the source code of this file.

Defines

#define BMZ_MAGIC   "BMZ"
#define BMZIP_VER   0x0110
#define BMZ_HEADER_SZ   (strlen(BMZ_MAGIC) + 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
#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_)

Typedefs

typedef unsigned char Byte
typedef long long unsigned Llu
typedef long unsigned Lu

Functions

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[])

Variables

static int s_no_mmap = 0
 Copyright (C) 2007 Luke Lu (Zvents, Inc.
static int s_verbosity = 0
static int s_bm_dump = 0
static int s_bm_hash = 0


Define Documentation

#define BMZ_A_LIST   2

Definition at line 48 of file bmzip.c.

#define BMZ_A_PACK   0

Definition at line 46 of file bmzip.c.

#define BMZ_A_UNPACK   1

Definition at line 47 of file bmzip.c.

#define BMZ_ALIGN ( _mem_,
_n_   )     (Byte *)(_mem_) + _n_ - (((size_t)(_mem_))%(_n_))

Definition at line 78 of file bmzip.c.

#define BMZ_HEADER_SZ   (strlen(BMZ_MAGIC) + 2 + 1 + 6 + 4)

Definition at line 44 of file bmzip.c.

#define BMZ_MAGIC   "BMZ"

Definition at line 42 of file bmzip.c.

#define BMZ_O_BM_ONLY   1

Definition at line 50 of file bmzip.c.

#define BMZ_O_STREAM   2

Definition at line 51 of file bmzip.c.

#define BMZ_READ_INT16 ( _p_,
_n_   ) 

Value:

_n_ = (*_p_++ << 8); \
  _n_ |= (*_p_++)

Definition at line 80 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 84 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 90 of file bmzip.c.

#define BMZ_WRITE_INT16 ( _p_,
_n_   ) 

Value:

*_p_++ = (Byte)(_n_ >> 8); \
  *_p_++ = (Byte)(_n_)

Definition at line 98 of file bmzip.c.

#define BMZ_WRITE_INT32 ( _p_,
_n_   ) 

Value:

*_p_++ = (Byte)(_n_ >> 24); \
  *_p_++ = (Byte)(_n_ >> 16); \
  *_p_++ = (Byte)(_n_ >> 8); \
  *_p_++ = (Byte)(_n_)

Definition at line 102 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); \
  *_p_++ = (Byte)(_n_)

Definition at line 108 of file bmzip.c.

#define BMZIP_VER   0x0110

Definition at line 43 of file bmzip.c.

#define DIE ( _fmt_,
...   ) 

Value:

do { \
  LOG(0, "fatal: " _fmt_, ##__VA_ARGS__); \
  exit(1); \
} while (0)

Definition at line 73 of file bmzip.c.

#define LOG ( _lvl_,
_fmt_,
...   ) 

Value:

if (s_verbosity >= _lvl_) do { \
  fprintf(stderr, "bmzip: %s: " _fmt_, __FUNCTION__, ##__VA_ARGS__); \
  if (errno) fprintf(stderr, ": %s", strerror(errno)); \
  putc('\n', stderr); \
} while (0)

Definition at line 63 of file bmzip.c.

#define WARN ( _fmt_,
...   ) 

Value:

do { \
  LOG(0, "warning: " _fmt_, ##__VA_ARGS__); \
} while (0)

Definition at line 69 of file bmzip.c.


Typedef Documentation

typedef unsigned char Byte

Definition at line 53 of file bmzip.c.

typedef long long unsigned Llu

Definition at line 56 of file bmzip.c.

typedef long unsigned Lu

Definition at line 57 of file bmzip.c.


Function Documentation

static int bm_hash ( const char *  name  )  [static]

Definition at line 395 of file bmzip.c.

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]

Definition at line 285 of file bmzip.c.

static void do_list ( int  fd  )  [static]

Definition at line 159 of file bmzip.c.

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]

Definition at line 177 of file bmzip.c.

static void do_unpack ( const void *  in,
size_t  in_len,
size_t  buf_len 
) [static]

Definition at line 238 of file bmzip.c.

static void input_from_file ( const char *  fname,
size_t  offset,
size_t  fp_len,
int  action,
int  options 
) [static]

Definition at line 377 of file bmzip.c.

static void input_from_stdin ( size_t  offset,
size_t  fp_len,
int  action,
int  options 
) [static]

Definition at line 364 of file bmzip.c.

int main ( int  ac,
char *  av[] 
)

Definition at line 426 of file bmzip.c.

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]

Definition at line 123 of file bmzip.c.

static void read_bmz_header ( int  fd,
Byte buf 
) [static]

Definition at line 117 of file bmzip.c.

static char* read_from_fd ( int  fd,
size_t *  len_p,
size_t *  size_p 
) [static]

Definition at line 323 of file bmzip.c.

static char* read_from_fp ( FILE *  fp,
size_t *  len_p,
size_t *  size_p 
) [static]

Definition at line 300 of file bmzip.c.

static void HT_NORETURN show_usage (  )  [static]

Definition at line 408 of file bmzip.c.

static void write_bmz_header ( int  fd,
size_t  in_len,
uint32_t  checksum,
Byte  options 
) [static]

Definition at line 143 of file bmzip.c.


Variable Documentation

int s_bm_dump = 0 [static]

Definition at line 60 of file bmzip.c.

int s_bm_hash = 0 [static]

Definition at line 61 of file bmzip.c.

int s_no_mmap = 0 [static]

Copyright (C) 2007 Luke Lu (Zvents, 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 2 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.

int s_verbosity = 0 [static]

Definition at line 59 of file bmzip.c.


Generated on Sat Aug 15 08:56:11 2009 for hypertable by  doxygen 1.5.9