CPPFLAGS= -I. -I./common
CFLAGS ?= -O3
CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow -Wstrict-aliasing=1 \
- -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef
+ -Wswitch-enum -Wdeclaration-after-statement -Wstrict-prototypes -Wundef -Wdocumentation
FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS)
BIT_flushBits(bitC);
}
-/*<===== Decompression =====>*/
+/* ====== Decompression ====== */
typedef struct {
U16 tableLog;
BYTE* op = ostart;
size_t fhSize = 0;
- if (cctx->stage == ZSTDcs_created) return ERROR(stage_wrong); /*< not even init ! */
+ if (cctx->stage == ZSTDcs_created) return ERROR(stage_wrong); /* init missing */
/* special case : empty frame */
if (cctx->stage == ZSTDcs_init) {
/**
* Constructs the suffix array of a given string.
- * @param T[0..n-1] The input string.
- * @param SA[0..n-1] The output array of suffixes.
+ * @param T [0..n-1] The input string.
+ * @param SA [0..n-1] The output array of suffixes.
* @param n The length of the given string.
* @param openMP enables OpenMP optimization.
* @return 0 if no error occurred, -1 or -2 otherwise.
/**
* Constructs the burrows-wheeler transformed string of a given string.
- * @param T[0..n-1] The input string.
- * @param U[0..n-1] The output string. (can be T)
- * @param A[0..n-1] The temporary array. (can be NULL)
+ * @param T [0..n-1] The input string.
+ * @param U [0..n-1] The output string. (can be T)
+ * @param A [0..n-1] The temporary array. (can be NULL)
* @param n The length of the given string.
* @param num_indexes The length of secondary indexes array. (can be NULL)
* @param indexes The secondary indexes array. (can be NULL)
/* Build DTables */
switch(LLtype)
{
- U32 max;
case bt_rle :
LLlog = 0;
FSE_buildDTable_rle(DTableLL, *ip++); break;
LLlog = LLbits;
FSE_buildDTable_raw(DTableLL, LLbits); break;
default :
- max = MaxLL;
- headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
- if (LLlog > LLFSELog) return (size_t)-ZSTD_ERROR_corruption;
- ip += headerSize;
- FSE_buildDTable(DTableLL, norm, max, LLlog);
- }
+ { U32 max = MaxLL;
+ headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
+ if (LLlog > LLFSELog) return (size_t)-ZSTD_ERROR_corruption;
+ ip += headerSize;
+ FSE_buildDTable(DTableLL, norm, max, LLlog);
+ } }
switch(Offtype)
{
- U32 max;
case bt_rle :
Offlog = 0;
if (ip > iend-2) return (size_t)-ZSTD_ERROR_SrcSize; /* min : "raw", hence no header, but at least xxLog bits */
Offlog = Offbits;
FSE_buildDTable_raw(DTableOffb, Offbits); break;
default :
- max = MaxOff;
- headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
- if (Offlog > OffFSELog) return (size_t)-ZSTD_ERROR_corruption;
- ip += headerSize;
- FSE_buildDTable(DTableOffb, norm, max, Offlog);
- }
+ { U32 max = MaxOff;
+ headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
+ if (Offlog > OffFSELog) return (size_t)-ZSTD_ERROR_corruption;
+ ip += headerSize;
+ FSE_buildDTable(DTableOffb, norm, max, Offlog);
+ } }
switch(MLtype)
{
- U32 max;
case bt_rle :
MLlog = 0;
if (ip > iend-2) return (size_t)-ZSTD_ERROR_SrcSize; /* min : "raw", hence no header, but at least xxLog bits */
MLlog = MLbits;
FSE_buildDTable_raw(DTableML, MLbits); break;
default :
- max = MaxML;
- headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
- if (MLlog > MLFSELog) return (size_t)-ZSTD_ERROR_corruption;
- ip += headerSize;
- FSE_buildDTable(DTableML, norm, max, MLlog);
- }
- }
+ { U32 max = MaxML;
+ headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
+ if (MLlog > MLFSELog) return (size_t)-ZSTD_ERROR_corruption;
+ ip += headerSize;
+ FSE_buildDTable(DTableML, norm, max, MLlog);
+ } } }
return ip-istart;
}
/* Build DTables */
switch(LLtype)
{
- U32 max;
case bt_rle :
LLlog = 0;
FSE_buildDTable_rle(DTableLL, *ip++); break;
LLlog = LLbits;
FSE_buildDTable_raw(DTableLL, LLbits); break;
default :
- max = MaxLL;
- headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (LLlog > LLFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableLL, norm, max, LLlog);
- }
+ { U32 max = MaxLL;
+ headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (LLlog > LLFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableLL, norm, max, LLlog);
+ } }
switch(Offtype)
{
- U32 max;
case bt_rle :
Offlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
Offlog = Offbits;
FSE_buildDTable_raw(DTableOffb, Offbits); break;
default :
- max = MaxOff;
- headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (Offlog > OffFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableOffb, norm, max, Offlog);
- }
+ { U32 max = MaxOff;
+ headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (Offlog > OffFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableOffb, norm, max, Offlog);
+ } }
switch(MLtype)
{
- U32 max;
case bt_rle :
MLlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
MLlog = MLbits;
FSE_buildDTable_raw(DTableML, MLbits); break;
default :
- max = MaxML;
- headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (MLlog > MLFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableML, norm, max, MLlog);
- }
- }
+ { U32 max = MaxML;
+ headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (MLlog > MLFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableML, norm, max, MLlog);
+ } } }
return ip-istart;
}
/* Build DTables */
switch(LLtype)
{
- U32 max;
case bt_rle :
LLlog = 0;
FSE_buildDTable_rle(DTableLL, *ip++); break;
LLlog = LLbits;
FSE_buildDTable_raw(DTableLL, LLbits); break;
default :
- max = MaxLL;
- headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (LLlog > LLFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableLL, norm, max, LLlog);
- }
+ { U32 max = MaxLL;
+ headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (LLlog > LLFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableLL, norm, max, LLlog);
+ } }
switch(Offtype)
{
- U32 max;
case bt_rle :
Offlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
Offlog = Offbits;
FSE_buildDTable_raw(DTableOffb, Offbits); break;
default :
- max = MaxOff;
- headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (Offlog > OffFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableOffb, norm, max, Offlog);
- }
+ { U32 max = MaxOff;
+ headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (Offlog > OffFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableOffb, norm, max, Offlog);
+ } }
switch(MLtype)
{
- U32 max;
case bt_rle :
MLlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
MLlog = MLbits;
FSE_buildDTable_raw(DTableML, MLbits); break;
default :
- max = MaxML;
- headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (MLlog > MLFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableML, norm, max, MLlog);
- }
- }
+ { U32 max = MaxML;
+ headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (MLlog > MLFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableML, norm, max, MLlog);
+ } } }
return ip-istart;
}
/* Build DTables */
switch(LLtype)
{
- U32 max;
case bt_rle :
LLlog = 0;
FSE_buildDTable_rle(DTableLL, *ip++); break;
LLlog = LLbits;
FSE_buildDTable_raw(DTableLL, LLbits); break;
default :
- max = MaxLL;
- headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (LLlog > LLFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableLL, norm, max, LLlog);
- }
+ { U32 max = MaxLL;
+ headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (LLlog > LLFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableLL, norm, max, LLlog);
+ } }
switch(Offtype)
{
- U32 max;
case bt_rle :
Offlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
Offlog = Offbits;
FSE_buildDTable_raw(DTableOffb, Offbits); break;
default :
- max = MaxOff;
- headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (Offlog > OffFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableOffb, norm, max, Offlog);
- }
+ { U32 max = MaxOff;
+ headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (Offlog > OffFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableOffb, norm, max, Offlog);
+ } }
switch(MLtype)
{
- U32 max;
case bt_rle :
MLlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
MLlog = MLbits;
FSE_buildDTable_raw(DTableML, MLbits); break;
default :
- max = MaxML;
- headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
- if (FSE_isError(headerSize)) return ERROR(GENERIC);
- if (MLlog > MLFSELog) return ERROR(corruption_detected);
- ip += headerSize;
- FSE_buildDTable(DTableML, norm, max, MLlog);
- }
- }
+ { U32 max = MaxML;
+ headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
+ if (MLlog > MLFSELog) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSE_buildDTable(DTableML, norm, max, MLlog);
+ } } }
return ip-istart;
}
* The function will report how many bytes were read or written by modifying *srcSizePtr and *maxDstSizePtr.
* Note that it may not consume the entire input, in which case it's up to the caller to call again the function with remaining input.
* The content of dst will be overwritten (up to *maxDstSizePtr) at each function call, so save its content if it matters or change dst .
-* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency)
+* return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency)
* or 0 when a frame is completely decoded
* or an error code, which can be tested using ZBUFF_isError().
*
/* Build DTables */
switch(LLtype)
{
- U32 max;
case FSEv05_ENCODING_RLE :
LLlog = 0;
FSEv05_buildDTable_rle(DTableLL, *ip++);
break;
case FSEv05_ENCODING_DYNAMIC :
default : /* impossible */
- max = MaxLL;
- headerSize = FSEv05_readNCount(norm, &max, &LLlog, ip, iend-ip);
- if (FSEv05_isError(headerSize)) return ERROR(GENERIC);
- if (LLlog > LLFSEv05Log) return ERROR(corruption_detected);
- ip += headerSize;
- FSEv05_buildDTable(DTableLL, norm, max, LLlog);
- }
+ { U32 max = MaxLL;
+ headerSize = FSEv05_readNCount(norm, &max, &LLlog, ip, iend-ip);
+ if (FSEv05_isError(headerSize)) return ERROR(GENERIC);
+ if (LLlog > LLFSEv05Log) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSEv05_buildDTable(DTableLL, norm, max, LLlog);
+ } }
switch(Offtype)
{
- U32 max;
case FSEv05_ENCODING_RLE :
Offlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
break;
case FSEv05_ENCODING_DYNAMIC :
default : /* impossible */
- max = MaxOff;
- headerSize = FSEv05_readNCount(norm, &max, &Offlog, ip, iend-ip);
- if (FSEv05_isError(headerSize)) return ERROR(GENERIC);
- if (Offlog > OffFSEv05Log) return ERROR(corruption_detected);
- ip += headerSize;
- FSEv05_buildDTable(DTableOffb, norm, max, Offlog);
- }
+ { U32 max = MaxOff;
+ headerSize = FSEv05_readNCount(norm, &max, &Offlog, ip, iend-ip);
+ if (FSEv05_isError(headerSize)) return ERROR(GENERIC);
+ if (Offlog > OffFSEv05Log) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSEv05_buildDTable(DTableOffb, norm, max, Offlog);
+ } }
switch(MLtype)
{
- U32 max;
case FSEv05_ENCODING_RLE :
MLlog = 0;
if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
break;
case FSEv05_ENCODING_DYNAMIC :
default : /* impossible */
- max = MaxML;
- headerSize = FSEv05_readNCount(norm, &max, &MLlog, ip, iend-ip);
- if (FSEv05_isError(headerSize)) return ERROR(GENERIC);
- if (MLlog > MLFSEv05Log) return ERROR(corruption_detected);
- ip += headerSize;
- FSEv05_buildDTable(DTableML, norm, max, MLlog);
- } }
+ { U32 max = MaxML;
+ headerSize = FSEv05_readNCount(norm, &max, &MLlog, ip, iend-ip);
+ if (FSEv05_isError(headerSize)) return ERROR(GENERIC);
+ if (MLlog > MLFSEv05Log) return ERROR(corruption_detected);
+ ip += headerSize;
+ FSEv05_buildDTable(DTableML, norm, max, MLlog);
+ } } }
return ip-istart;
}
* The function will report how many bytes were read or written by modifying *srcSizePtr and *maxDstSizePtr.
* Note that it may not consume the entire input, in which case it's up to the caller to call again the function with remaining input.
* The content of dst will be overwritten (up to *maxDstSizePtr) at each function call, so save its content if it matters or change dst .
-* @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency)
+* return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to improve latency)
* or 0 when a frame is completely decoded
* or an error code, which can be tested using ZBUFFv05_isError().
*
*******************************************/
-/*<===== Decompression =====>*/
+/* ====== Decompression ====== */
typedef struct {
U16 tableLog;
/* faster, but works only if nbBits is always >= 1 (otherwise, result will be corrupted) */
-/*<===== Decompression =====>*/
+/* ====== Decompression ====== */
typedef struct {
U16 tableLog;
* Explicit memory management
***************************************/
/** Compression context */
-typedef struct ZSTD_CCtx_s ZSTD_CCtx; /*< incomplete type */
+typedef struct ZSTD_CCtx_s ZSTD_CCtx;
ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx);
ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);
/** Decompression context */
-typedef struct ZSTD_DCtx_s ZSTD_DCtx; /*< incomplete type */
+typedef struct ZSTD_DCtx_s ZSTD_DCtx;
ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx);
/*--- Types ---*/
-typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /*< from faster to stronger */
+typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt } ZSTD_strategy; /* from faster to stronger */
typedef struct {
unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */
#define MB *(1 <<20)
#define GB *(1U<<30)
-static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-30));
+static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
static U32 g_compressibilityDefault = 50;
}
/* No input filename ==> use stdin and stdout */
- filenameIdx += !filenameIdx; /*< default input is stdin */
- if (!strcmp(filenameTable[0], stdinmark) && !outFileName) outFileName = stdoutmark; /*< when input is stdin, default output is stdout */
+ filenameIdx += !filenameIdx; /* filenameTable[0] is stdin by default */
+ if (!strcmp(filenameTable[0], stdinmark) && !outFileName) outFileName = stdoutmark; /* when input is stdin, default output is stdout */
/* Check if input/output defined as console; trigger an error in this case */
if (!strcmp(filenameTable[0], stdinmark) && IS_CONSOLE(stdin) ) CLEAN_RETURN(badusage(programName));