Exemplo n.º 1
0
int
bmz_pack_mask(const void *in, size_t in_len, void *out, size_t *out_len_p,
              size_t offset, size_t fp_len, unsigned flags, void *work_mem,
              size_t b) {
  BMZ_PACK_BODY(bmz_bm_pack_mask(in, in_len, dst, &tlen,
                offset, fp_len, work_mem_aligned, b));
}
Exemplo n.º 2
0
static void
do_pack(const void *in, size_t in_len, size_t buf_len,
        size_t offset, size_t fp_len, Byte options) {
  size_t buflen = bmz_pack_buflen(in_len), out_len = buflen;
  size_t worklen = bmz_pack_worklen(in_len, fp_len);
  int ret, bm_only = (options & BMZ_O_BM_ONLY) || s_bm_dump;
  Byte *out, *work_mem;

  if (bm_only) {
    out_len = in_len + 1;

    if (buf_len > in_len + worklen) {
      out = (Byte *)in + in_len;
      work_mem = out + out_len;
    }
    else {
      out = malloc(worklen); /* bmz_pack_worklen includes out_len for bm */

      if (!out)
        DIE("error allocating %lu bytes memory", (Lu)worklen);

      work_mem = out + out_len;
    }
    /* calling internal API need to align work memory */
    work_mem = BMZ_ALIGN(work_mem, 8);
  }
  else if (buf_len > buflen + worklen) {
    work_mem = (Byte *)in + buflen;
    out = (Byte *)in; /* inplace */
  }
  else {
    out = malloc(buflen + worklen);

    if (!out)
      DIE("error allocating %lu bytes memory", (Lu)buflen + worklen);

    work_mem = out + buflen;
  }

  if (bm_only) {
    ret = bmz_bm_pack_mask(in, in_len, out, &out_len, offset, fp_len,
                           work_mem, 257);
    if (ret != BMZ_E_OK)
      DIE("error encoding bm output (error %d)", ret);

    if (s_bm_dump) {
      if ((ret = bmz_bm_dump(out, out_len)) != BMZ_E_OK)
        WARN("error dumping bm encoding (ret=%d)", ret);

      return;
    }
  }
  else if ((ret = bmz_pack(in, in_len, out, &out_len, offset, fp_len,
                           (s_bm_hash << 24), work_mem))
           != BMZ_E_OK) {
    DIE("error compressing input (error %d)", ret);
  }
  write_bmz_header(1, in_len, bmz_checksum(out, out_len), options);
  write(1, out, out_len);
}
Exemplo n.º 3
0
static void
test_bm_mask(const char *in, size_t len, char *out, size_t *len_p,
             void *work_mem) {
  bmz_bm_pack_mask(in, len, out, len_p, s_offset, s_fp_len, work_mem, s_b1);
  dump_bm("mask", out, *len_p);
}