Skip to content

Commit

Permalink
Merge pull request #2 from chenyong111/master
Browse files Browse the repository at this point in the history
update minilzo sample, modify the padding definition
  • Loading branch information
armink authored Mar 10, 2018
2 parents 9620f42 + e277c71 commit fda5726
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions minilzo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@


#ifndef __MINILZO_H_INCLUDED
#define __MINILZO_H_INCLUDED 1
#define __MINILZO_H_INCLUDED 1

#define MINILZO_VERSION 0x20a0 /* 2.10 */
#define MINILZO_VERSION 0x20a0 /* 2.10 */

/* we must provide a little more output space in case that compression is not possible */
#define MINILZO_BUFFER_PADDING(x) ((x) / 16 + 64 + 3)

#if defined(__LZOCONF_H_INCLUDED)
# error "you cannot use both LZO and miniLZO"
Expand Down
10 changes: 5 additions & 5 deletions minilzo_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define DCOMPRESS_BUFFER_SIZE 4096

/* we must provide a little more output space in case that compression is not possible */
#define COMPRESS_BUFFER_PADDING (COMPRESS_BUFFER_SIZE / 16 + 64 + 3)
#define BUFFER_PADDING MINILZO_BUFFER_PADDING(COMPRESS_BUFFER_SIZE)

static int minilzo_compress_file(int fd_in, int fd_out)
{
Expand All @@ -65,7 +65,7 @@ static int minilzo_compress_file(int fd_in, int fd_out)
file_size = lseek(fd_in, 0, SEEK_END);
lseek(fd_in, 0, SEEK_SET);

cmprs_buffer = (rt_uint8_t *) malloc(COMPRESS_BUFFER_SIZE + COMPRESS_BUFFER_PADDING);
cmprs_buffer = (rt_uint8_t *) malloc(COMPRESS_BUFFER_SIZE + BUFFER_PADDING);
buffer = (rt_uint8_t *) malloc(COMPRESS_BUFFER_SIZE);
if (!cmprs_buffer || !buffer)
{
Expand All @@ -87,7 +87,7 @@ static int minilzo_compress_file(int fd_in, int fd_out)
}

memset(buffer, 0x00, COMPRESS_BUFFER_SIZE);
memset(cmprs_buffer, 0x00, COMPRESS_BUFFER_SIZE + COMPRESS_BUFFER_PADDING);
memset(cmprs_buffer, 0x00, COMPRESS_BUFFER_SIZE + BUFFER_PADDING);

read(fd_in, buffer, block_size);

Expand Down Expand Up @@ -155,7 +155,7 @@ static int minilzo_decompress_file(int fd_in, int fd_out)
}

dcmprs_buffer = (rt_uint8_t *) malloc(DCOMPRESS_BUFFER_SIZE);
buffer = (rt_uint8_t *) malloc(DCOMPRESS_BUFFER_SIZE + COMPRESS_BUFFER_PADDING);
buffer = (rt_uint8_t *) malloc(DCOMPRESS_BUFFER_SIZE + BUFFER_PADDING);
if (!dcmprs_buffer || !buffer)
{
rt_kprintf("[minilzo] No memory for dcmprs_buffer or buffer!\n");
Expand All @@ -170,7 +170,7 @@ static int minilzo_decompress_file(int fd_in, int fd_out)
read(fd_in, buffer_hdr, BLOCK_HEADER_SIZE);
block_size = buffer_hdr[0] * (1 << 24) + buffer_hdr[1] * (1 << 16) + buffer_hdr[2] * (1 << 8) + buffer_hdr[3];

memset(buffer, 0x00, COMPRESS_BUFFER_SIZE + COMPRESS_BUFFER_PADDING);
memset(buffer, 0x00, COMPRESS_BUFFER_SIZE + BUFFER_PADDING);
memset(dcmprs_buffer, 0x00, DCOMPRESS_BUFFER_SIZE);

read(fd_in, buffer, block_size);
Expand Down

0 comments on commit fda5726

Please # to comment.