diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2022-07-31 13:28:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-31 13:28:28 (GMT) |
commit | d343a3685233f3c46c20bfeb7e8674de9d8175fc (patch) | |
tree | c0b757c6b5adad607fabde8fd36d951c8dcbeb81 /lib/lz4.c | |
parent | 6c8508323a87e7ce0bdea57ab18def17000effab (diff) | |
parent | 5d80375deddf33f2392eb2ea678cf2e203bb24fb (diff) | |
download | lz4-d343a3685233f3c46c20bfeb7e8674de9d8175fc.zip lz4-d343a3685233f3c46c20bfeb7e8674de9d8175fc.tar.gz lz4-d343a3685233f3c46c20bfeb7e8674de9d8175fc.tar.bz2 |
Merge pull request #1123 from t-mat/memfunc-macros
New macro for memcpy, memmove and memset
Diffstat (limited to 'lib/lz4.c')
-rw-r--r-- | lib/lz4.c | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -206,7 +206,10 @@ void LZ4_free(void* p); #endif #include <string.h> /* memset, memcpy */ -#define MEM_INIT(p,v,s) memset((p),(v),(s)) +#if !defined(LZ4_memset) +# define LZ4_memset(p,v,s) memset((p),(v),(s)) +#endif +#define MEM_INIT(p,v,s) LZ4_memset((p),(v),(s)) /*-************************************ @@ -317,10 +320,20 @@ typedef enum { * memcpy() as if it were standard compliant, so it can inline it in freestanding * environments. This is needed when decompressing the Linux Kernel, for example. */ -#if defined(__GNUC__) && (__GNUC__ >= 4) -#define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size) -#else -#define LZ4_memcpy(dst, src, size) memcpy(dst, src, size) +#if !defined(LZ4_memcpy) +# if defined(__GNUC__) && (__GNUC__ >= 4) +# define LZ4_memcpy(dst, src, size) __builtin_memcpy(dst, src, size) +# else +# define LZ4_memcpy(dst, src, size) memcpy(dst, src, size) +# endif +#endif + +#if !defined(LZ4_memmove) +# if defined(__GNUC__) && (__GNUC__ >= 4) +# define LZ4_memmove __builtin_memmove +# else +# define LZ4_memmove memmove +# endif #endif static unsigned LZ4_isLittleEndian(void) @@ -1703,7 +1716,7 @@ int LZ4_saveDict (LZ4_stream_t* LZ4_dict, char* safeBuffer, int dictSize) if (dictSize > 0) { const BYTE* const previousDictEnd = dict->dictionary + dict->dictSize; assert(dict->dictionary); - memmove(safeBuffer, previousDictEnd - dictSize, dictSize); + LZ4_memmove(safeBuffer, previousDictEnd - dictSize, dictSize); } dict->dictionary = (const BYTE*)safeBuffer; @@ -1920,7 +1933,7 @@ LZ4_decompress_generic( if (length <= (size_t)(lowPrefix-match)) { /* match fits entirely within external dictionary : just copy */ - memmove(op, dictEnd - (lowPrefix-match), length); + LZ4_memmove(op, dictEnd - (lowPrefix-match), length); op += length; } else { /* match stretches into both external dictionary and current block */ @@ -2064,7 +2077,7 @@ LZ4_decompress_generic( goto _output_error; } } - memmove(op, ip, length); /* supports overlapping memory regions; only matters for in-place decompression scenarios */ + LZ4_memmove(op, ip, length); /* supports overlapping memory regions; only matters for in-place decompression scenarios */ ip += length; op += length; /* Necessarily EOF when !partialDecoding. @@ -2109,7 +2122,7 @@ LZ4_decompress_generic( if (length <= (size_t)(lowPrefix-match)) { /* match fits entirely within external dictionary : just copy */ - memmove(op, dictEnd - (lowPrefix-match), length); + LZ4_memmove(op, dictEnd - (lowPrefix-match), length); op += length; } else { /* match stretches into both external dictionary and current block */ |