Exemple #1
0
static VALUE rb_lzfx_compress(VALUE self, VALUE input) {
  unsigned char *compressed, *data;
  int out_length, data_length;
  int retcode;
  VALUE retval;

  Check_Type(input, T_STRING);
  data = StringValuePtr(input);
  data_length = RSTRING_LEN(input);

  if (data_length < 1) {
    return Qnil;
  }

  out_length = data_length * COFFICIENT_OF_BUFFER;
  compressed = malloc(out_length);

  retcode = lzfx_compress(data, data_length, compressed, &out_length);

  if(retcode < 0) {
    ruby_xfree(compressed);
    return Qnil;
  }

  retval = rb_str_new(compressed, out_length);

  ruby_xfree(compressed);

  return retval;
}
Exemple #2
0
int
lz_fx_compress(void *src, uint64_t srclen, void *dst, uint64_t *dstlen,
	       int level, uchar_t chdr, int btype, void *data)
{
	int rv;
	struct lzfx_params *lzdat = (struct lzfx_params *)data;
	unsigned int _srclen = srclen;
	unsigned int _dstlen = *dstlen;

	/*
	 * Ignore compressed data in fast modes.
	 */
	if (level < 7 && PC_TYPE(btype) == TYPE_COMPRESSED)
		return (-1);

	rv = lzfx_compress(src, _srclen, dst, &_dstlen, lzdat->htab_bits);
	if (rv != 0) {
		if (rv != LZFX_ESIZE)
			lz_fx_err(rv);
		return (-1);
	}
	*dstlen = _dstlen;

	return (0);
}
/// This is the entry-point function for the executable
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    char ibuf[16], obuf[16];
    // Call lzfx function, which does nothing useful other than to
    // prove whether any function can be called.
    int n = lzfx_compress((void*)(*ibuf), 0, (void*)(*obuf), 0);
    // If we successfully return from the lzfx function, then exit 
    // with a distinctive code that the caller can recognize.  If the caller sees
    // this code, then it indicates that there was no missing dependency error.
    ExitProcess(23445);
}
int
lz_fx_compress(void *src, uint64_t srclen, void *dst, uint64_t *dstlen,
	       int level, uchar_t chdr, void *data)
{
	int rv;
	struct lzfx_params *lzdat = (struct lzfx_params *)data;
	unsigned int _srclen = srclen;
	unsigned int _dstlen = *dstlen;

	rv = lzfx_compress(src, _srclen, dst, &_dstlen, lzdat->htab_bits);
	if (rv != 0) {
		if (rv != LZFX_ESIZE)
			lz_fx_err(rv);
		return (-1);
	}
	*dstlen = _dstlen;

	return (0);
}