int lzo_decompress_dict(const lzo_bytep in, lzo_uint in_len, lzo_bytep out, lzo_uintp out_len, lzo_voidp wrkmem /* NOT USED */, const lzo_bytep dict, lzo_uint dict_len) { return lzo1x_decompress_dict_safe(in, in_len, out, out_len, wrkmem, dict, dict_len); }
int do_file ( const char *in_name, int level ) { int r; lzo_bytep in; lzo_bytep out; lzo_bytep newb; lzo_bytep wrkmem; lzo_uint in_len; lzo_uint out_len; lzo_uint new_len; long l; FILE *f; /* * Step 1: open the input file */ f = fopen(in_name,"rb"); if (f == 0) { printf("%s: cannot open file %s\n", progname, in_name); return 0; /* no error */ } fseek(f,0,SEEK_END); l = ftell(f); fseek(f,0,SEEK_SET); if (l <= 0) { printf("%s: %s: empty file -- skipping\n", progname, in_name); fclose(f); return 0; } in_len = (lzo_uint) l; /* * Step 2: allocate compression buffers and read the file */ in = (lzo_bytep) lzo_malloc(in_len); out = (lzo_bytep) lzo_malloc(in_len + in_len / 16 + 64 + 3); newb = (lzo_bytep) lzo_malloc(in_len); wrkmem = (lzo_bytep) lzo_malloc(LZO1X_999_MEM_COMPRESS); if (in == NULL || out == NULL || newb == NULL || wrkmem == NULL) { printf("%s: out of memory\n", progname); exit(1); } in_len = (lzo_uint) lzo_fread(f,in,in_len); fclose(f); /* * Step 3: compress from `in' to `out' with LZO1X-999 */ r = lzo1x_999_compress_level(in,in_len,out,&out_len,wrkmem, dict, dict_len, 0, level); if (r != LZO_E_OK) { /* this should NEVER happen */ printf("internal error - compression failed: %d\n", r); return 1; } print_file(in_name,in_len,out_len); /* * Step 4: decompress again, now going from `out' to `newb' */ new_len = in_len; r = lzo1x_decompress_dict_safe(out,out_len,newb,&new_len,NULL,dict,dict_len); if (r != LZO_E_OK) { /* this should NEVER happen */ printf("internal error - decompression failed: %d\n", r); return 1; } /* * Step 5: verify decompression */ if (new_len != in_len || lzo_memcmp(in,newb,in_len) != 0) { /* this should NEVER happen */ printf("internal error - decompression data error\n"); return 1; } /* free buffers in reverse order to help malloc() */ lzo_free(wrkmem); lzo_free(newb); lzo_free(out); lzo_free(in); return 0; }