X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Flizard.h;h=c3141ecc32a03229a3f15571740354bcb35155ec;hb=83b3a0000e1472236aec517e6a93c68c92cb7c64;hp=f45207251c9d73feb4e7af3bcb02fc50962ee6d6;hpb=fdb438738b41d339e87aaa0c93620a45660ffa5d;p=libucw.git diff --git a/ucw/lizard.h b/ucw/lizard.h index f4520725..c3141ecc 100644 --- a/ucw/lizard.h +++ b/ucw/lizard.h @@ -10,6 +10,15 @@ #ifndef _UCW_LIZARD_H #define _UCW_LIZARD_H +#ifdef CONFIG_UCW_CLEAN_ABI +#define adler32_update ucw_adler32_update +#define lizard_alloc ucw_lizard_alloc +#define lizard_compress ucw_lizard_compress +#define lizard_decompress ucw_lizard_decompress +#define lizard_decompress_safe ucw_lizard_decompress_safe +#define lizard_free ucw_lizard_free +#endif + /*** * [[basic]] * Basic application @@ -59,7 +68,7 @@ * * Use @lizard_decompress() to get the original data. **/ -int lizard_compress(const byte *in, uns in_len, byte *out); +int lizard_compress(const byte *in, uint in_len, byte *out); /** * Decompress data previously compressed by @lizard_compress(). @@ -87,20 +96,37 @@ int lizard_decompress(const byte *in, byte *out); struct lizard_buffer; /** Type of the output buffer for @lizard_decompress_safe(). **/ struct lizard_buffer *lizard_alloc(void); /** Get me a new <>. **/ -void lizard_free(struct lizard_buffer *buf); /** Return memory used by a <>. **/ +/** + * Return memory used by a <>. + * It frees even the data stored in it (the result of + * @lizard_decompress_safe() call that used this buffer). + **/ +void lizard_free(struct lizard_buffer *buf); /** - * Decompress data previously compressed by @lizard_compress(). - * Input is taken from @in. @buf is used to store the output. - * You need to provide the length of the uncompressed data in @expected_length. + * This one acts much like @lizard_decompress(). The difference is it + * checks the data to be of correct length (therefore it will not + * crash on invalid data). + * + * It decompresses data provided by @in. The @buf is used to get the + * memory for output (you get one by @lizard_alloc()). + * + * The pointer to decompressed data is returned. To free it, free the + * buffer by @lizard_free(). + * + * In the case of error, NULL is returned. In that case, `errno` is + * set either to `EINVAL` (expected_length does not match) or to + * `EFAULT` (a segfault has been caught while decompressing -- it + * probably means expected_length was set way too low). Both cases + * suggest either wrongly computed length or data corruption. * - * The pointer to data is returned. + * The @buf argument may be reused for multiple decompresses. However, + * the data will be overwritten by the next call. * - * If an error occurs, NULL is returned and `errno` is set. - * `EINVAL` means the actual length does not match @expected_length. - * `EFAULT` means a segfault was encountered while decompressing (probably @expected_length was way too low). + * Beware this function is not thread-safe and is not even reentrant + * (because of internal segfault handling). **/ -byte *lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expected_length); +byte *lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uint expected_length); /* adler32.c */ @@ -118,12 +144,12 @@ byte *lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expe * @adler is the old value, @byte points to @len bytes of data to update with. * Result is returned. **/ -uns adler32_update(uns adler, const byte *ptr, uns len); +uint adler32_update(uint adler, const byte *ptr, uint len); /** * Compute the Adler-32 checksum of a block of data. **/ -static inline uns adler32(const byte *buf, uns len) +static inline uint adler32(const byte *buf, uint len) { return adler32_update(1, buf, len); }