int64_t lzbench_lzo1a_compress(char *inbuf, size_t insize, char *outbuf, size_t outsize, size_t level, size_t, char* workmem) { lzo_uint lzo_complen = 0; int res; if (!workmem) return 0; if (level == 99) res = lzo1a_99_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); else res = lzo1a_compress((uint8_t*)inbuf, insize, (uint8_t*)outbuf, &lzo_complen, (void*)workmem); if (res != LZO_E_OK) return 0; return lzo_complen; }
compr *lzo_compress(unsigned char *buf, int buflen) { int r; lzo_bytep in; lzo_bytep out; lzo_bytep wrkmem; lzo_uint out_len; compr *retdata; pthread_mutex_lock(&lzo_mutex); retdata = s_malloc(sizeof(compr)); in = (lzo_bytep) buf; out = (lzo_bytep) lzo_malloc(OUT_LEN); wrkmem = (lzo_bytep) lzo_malloc(LZO1A_MEM_COMPRESS); if (in == NULL || out == NULL || wrkmem == NULL) { LFATAL("out of memory\n"); exit(3); } r = lzo1a_compress(in, buflen, out, &out_len, wrkmem); if (r != LZO_E_OK) { /* this should NEVER happen */ LFATAL("internal error - compression failed: %d\n", r); exit(2); } // LDEBUG("Compressed %i bytes to %lu bytes",buflen,(unsigned long)out_len); if ( out_len > buflen ) { retdata->data = s_malloc(buflen+1); memcpy(&retdata->data[1], buf, buflen); retdata->size = buflen+1; retdata->data[0]=0; } else { retdata->data = s_malloc(out_len+1); retdata->size = out_len+1; memcpy(&retdata->data[1], out, out_len); retdata->data[0]='L'; } lzo_free(wrkmem); lzo_free(out); pthread_mutex_unlock(&lzo_mutex); return retdata; }