v0.40
This commit is contained in:
parent
1af4b85a22
commit
0433a6bc0a
12 changed files with 4843 additions and 4686 deletions
186
UnAlz.cpp
186
UnAlz.cpp
|
@ -87,6 +87,7 @@ static const char* errorstrtable[]=
|
||||||
"no error", // ERR_NOERR
|
"no error", // ERR_NOERR
|
||||||
"can't open file", // ERR_CANT_OPEN_FILE
|
"can't open file", // ERR_CANT_OPEN_FILE
|
||||||
"corrupted file", // ERR_CORRUPTED_FILE
|
"corrupted file", // ERR_CORRUPTED_FILE
|
||||||
|
"not alz file", // ERR_NOT_ALZ_FILE
|
||||||
"can't read signature", // ERR_CANT_READ_SIG
|
"can't read signature", // ERR_CANT_READ_SIG
|
||||||
"can't read file", // ERR_CANT_READ_FILE
|
"can't read file", // ERR_CANT_READ_FILE
|
||||||
"error at read header", // ERR_AT_READ_HEADER
|
"error at read header", // ERR_AT_READ_HEADER
|
||||||
|
@ -100,6 +101,9 @@ static const char* errorstrtable[]=
|
||||||
"memory allocation failed", // ERR_MEM_ALLOC_FAILED,
|
"memory allocation failed", // ERR_MEM_ALLOC_FAILED,
|
||||||
"file read error", // ERR_FILE_READ_ERROR,
|
"file read error", // ERR_FILE_READ_ERROR,
|
||||||
"inflate failed", // ERR_INFLATE_FAILED,
|
"inflate failed", // ERR_INFLATE_FAILED,
|
||||||
|
"bzip2 decompress failed", // ERR_BZIP2_FAILED,
|
||||||
|
"invalid file CRC", // ERR_INVALID_FILE_CRC
|
||||||
|
"unknown compression method", // ERR_UNKNOWN_COMPRESSION_METHOD
|
||||||
|
|
||||||
"iconv-can't open iconv", // ERR_ICONV_CANT_OPEN,
|
"iconv-can't open iconv", // ERR_ICONV_CANT_OPEN,
|
||||||
"iconv-invalid multisequence of characters", // ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS,
|
"iconv-invalid multisequence of characters", // ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS,
|
||||||
|
@ -107,9 +111,9 @@ static const char* errorstrtable[]=
|
||||||
"iconv-not enough space of buffer to convert", // ERR_ICONV_NOT_ENOUGH_SPACE_OF_BUFFER_TO_CONVERT,
|
"iconv-not enough space of buffer to convert", // ERR_ICONV_NOT_ENOUGH_SPACE_OF_BUFFER_TO_CONVERT,
|
||||||
"iconv-etc", // ERR_ICONV_ETC,
|
"iconv-etc", // ERR_ICONV_ETC,
|
||||||
|
|
||||||
"password not set", //ERR_PASSWD_NOT_SET,
|
"password was not set", // ERR_PASSWD_NOT_SET,
|
||||||
"invalid password", //ERR_INVALID_PASSWD,
|
"invalid password", // ERR_INVALID_PASSWD,
|
||||||
"User Aborted",
|
"user aborted",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,6 +214,8 @@ BOOL CUnAlz::Open(const char* szPathName)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOL bValidAlzHeader = FALSE;
|
||||||
|
|
||||||
// file 분석시작..
|
// file 분석시작..
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
@ -225,11 +231,18 @@ BOOL CUnAlz::Open(const char* szPathName)
|
||||||
}
|
}
|
||||||
if(sig==SIG_ERROR)
|
if(sig==SIG_ERROR)
|
||||||
{
|
{
|
||||||
m_nErr = ERR_CORRUPTED_FILE;
|
if(bValidAlzHeader)
|
||||||
|
m_nErr = ERR_CORRUPTED_FILE; // 손상된 파일
|
||||||
|
else
|
||||||
|
m_nErr = ERR_NOT_ALZ_FILE; // alz 파일이 아니다.
|
||||||
return FALSE; // 깨진 파일..
|
return FALSE; // 깨진 파일..
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sig==SIG_ALZ_FILE_HEADER) ret = ReadAlzFileHeader();
|
if(sig==SIG_ALZ_FILE_HEADER)
|
||||||
|
{
|
||||||
|
ret = ReadAlzFileHeader();
|
||||||
|
bValidAlzHeader = TRUE; // alz 파일은 맞다.
|
||||||
|
}
|
||||||
else if(sig==SIG_LOCAL_FILE_HEADER) ret = ReadLocalFileheader();
|
else if(sig==SIG_LOCAL_FILE_HEADER) ret = ReadLocalFileheader();
|
||||||
else if(sig==SIG_CENTRAL_DIRECTORY_STRUCTURE) ret = ReadCentralDirectoryStructure();
|
else if(sig==SIG_CENTRAL_DIRECTORY_STRUCTURE) ret = ReadCentralDirectoryStructure();
|
||||||
else if(sig==SIG_ENDOF_CENTRAL_DIRECTORY_RECORD) ret = ReadEndofCentralDirectoryRecord();
|
else if(sig==SIG_ENDOF_CENTRAL_DIRECTORY_RECORD) ret = ReadEndofCentralDirectoryRecord();
|
||||||
|
@ -340,9 +353,9 @@ BOOL CUnAlz::ReadLocalFileheader()
|
||||||
if(byteLen)
|
if(byteLen)
|
||||||
{
|
{
|
||||||
FRead(&(zipHeader.compressionMethod), sizeof(zipHeader.compressionMethod));
|
FRead(&(zipHeader.compressionMethod), sizeof(zipHeader.compressionMethod));
|
||||||
FRead(&(zipHeader.unknown3), sizeof(zipHeader.unknown3));
|
FRead(&(zipHeader.unknown), sizeof(zipHeader.unknown));
|
||||||
FRead(&(zipHeader.unknown4), sizeof(zipHeader.unknown4));
|
FRead(&(zipHeader.fileCRC), sizeof(zipHeader.fileCRC));
|
||||||
FRead(&(zipHeader.passwordCRC), sizeof(zipHeader.passwordCRC));
|
// FRead(&(zipHeader.passwordCRC), sizeof(zipHeader.passwordCRC));
|
||||||
|
|
||||||
FRead(&(zipHeader.compressedSize), byteLen);
|
FRead(&(zipHeader.compressedSize), byteLen);
|
||||||
FRead(&(zipHeader.uncompressedSize), byteLen); // 압축 사이즈가 없다.
|
FRead(&(zipHeader.uncompressedSize), byteLen); // 압축 사이즈가 없다.
|
||||||
|
@ -354,7 +367,7 @@ BOOL CUnAlz::ReadLocalFileheader()
|
||||||
zipHeader.uncompressedSize = unalz_le64toh(zipHeader.uncompressedSize);
|
zipHeader.uncompressedSize = unalz_le64toh(zipHeader.uncompressedSize);
|
||||||
|
|
||||||
// FILE NAME
|
// FILE NAME
|
||||||
zipHeader.fileName = (char*)malloc(zipHeader.head.fileNameLength+1);
|
zipHeader.fileName = (char*)malloc(zipHeader.head.fileNameLength+sizeof(char));
|
||||||
if(zipHeader.fileName==NULL)
|
if(zipHeader.fileName==NULL)
|
||||||
{
|
{
|
||||||
m_nErr = ERR_INVALID_FILENAME_LENGTH;
|
m_nErr = ERR_INVALID_FILENAME_LENGTH;
|
||||||
|
@ -415,7 +428,14 @@ BOOL CUnAlz::ReadLocalFileheader()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
outbuf[ICONV_BUF_SIZE-oleft] = 0;
|
outbuf[ICONV_BUF_SIZE-oleft] = 0;
|
||||||
strcpy(zipHeader.fileName, outbuf);
|
if(zipHeader.fileName) free(zipHeader.fileName);
|
||||||
|
zipHeader.fileName = strdup(outbuf);
|
||||||
|
if (zipHeader.fileName == NULL)
|
||||||
|
{
|
||||||
|
m_nErr = ERR_ICONV_ETC;
|
||||||
|
iconv_close(cd);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
// printf("\n Converted File Name : %s", outbuf);
|
// printf("\n Converted File Name : %s", outbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -576,6 +596,11 @@ BOOL CUnAlz::SetCurrentFile(const char* szFileName)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CUnAlz::SetCurrentFile(FileList::iterator newPos)
|
||||||
|
{
|
||||||
|
m_posCur = newPos;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef MAX_WBITS
|
#ifndef MAX_WBITS
|
||||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||||
#endif
|
#endif
|
||||||
|
@ -692,9 +717,12 @@ BOOL CUnAlz::ExtractTo(SExtractDest* dest)
|
||||||
{
|
{
|
||||||
ret = ExtractDeflate2(dest, *m_posCur); // deflate
|
ret = ExtractDeflate2(dest, *m_posCur); // deflate
|
||||||
}
|
}
|
||||||
else
|
else // COMP_UNKNOWN
|
||||||
{
|
{
|
||||||
ASSERT(0); // 새로운 방법 ???
|
// alzip 5.6 부터 추가된 포맷(5.5 에서는 풀지 못한다. 영문 5.51 은 푼다 )
|
||||||
|
// 하지만 어떤 버전에서 이 포맷을 만들어 내는지 정확히 알 수 없다.
|
||||||
|
m_nErr = ERR_UNKNOWN_COMPRESSION_METHOD;
|
||||||
|
ASSERT(0);
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -887,6 +915,7 @@ int CUnAlz::WriteToDest(SExtractDest* dest, BYTE* buf, int nSize)
|
||||||
}
|
}
|
||||||
else if(dest->nType==ET_MEM)
|
else if(dest->nType==ET_MEM)
|
||||||
{
|
{
|
||||||
|
if(dest->buf==NULL) return nSize; // 대상이 NULL 이다... 압축푸는 시늉만 한다..
|
||||||
if(dest->bufpos+nSize >dest->bufsize) // 에러.. 버퍼가 넘쳤다.
|
if(dest->bufpos+nSize >dest->bufsize) // 에러.. 버퍼가 넘쳤다.
|
||||||
{
|
{
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
@ -1006,14 +1035,15 @@ END :
|
||||||
#define BUF_LEN (4096*2)
|
#define BUF_LEN (4096*2)
|
||||||
BOOL CUnAlz::ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file)
|
BOOL CUnAlz::ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
{
|
{
|
||||||
BOOL ret = FALSE;
|
BOOL ret = FALSE;
|
||||||
BYTE buf[BUF_LEN];
|
BYTE buf[BUF_LEN];
|
||||||
INT64 read;
|
INT64 read;
|
||||||
INT64 sizeToRead;
|
INT64 sizeToRead;
|
||||||
INT64 bufLen = BUF_LEN;
|
INT64 bufLen = BUF_LEN;
|
||||||
INT64 nWritten = 0;
|
INT64 nWritten = 0;
|
||||||
BOOL bHalt = FALSE;
|
BOOL bHalt = FALSE;
|
||||||
BOOL bIsEncrypted = IsEncryptedFile(); // 암호걸린 파일인가?
|
BOOL bIsEncrypted = IsEncryptedFile(); // 암호걸린 파일인가?
|
||||||
|
UINT32 dwCRC32= 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1022,6 +1052,7 @@ BOOL CUnAlz::ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
|
|
||||||
sizeToRead = file.compressedSize; // 읽을 크기.
|
sizeToRead = file.compressedSize; // 읽을 크기.
|
||||||
|
|
||||||
|
m_nErr = ERR_NOERR;
|
||||||
while(sizeToRead)
|
while(sizeToRead)
|
||||||
{
|
{
|
||||||
read = min(sizeToRead, bufLen);
|
read = min(sizeToRead, bufLen);
|
||||||
|
@ -1033,6 +1064,8 @@ BOOL CUnAlz::ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
if(bIsEncrypted)
|
if(bIsEncrypted)
|
||||||
DecryptingData((int)read, buf); // xf86
|
DecryptingData((int)read, buf); // xf86
|
||||||
|
|
||||||
|
dwCRC32 = crc32(dwCRC32, buf, (UINT)(read));
|
||||||
|
|
||||||
WriteToDest(dest, buf, (int)read);
|
WriteToDest(dest, buf, (int)read);
|
||||||
//fwrite(buf, read, 1, fp);
|
//fwrite(buf, read, 1, fp);
|
||||||
sizeToRead -= read;
|
sizeToRead -= read;
|
||||||
|
@ -1051,7 +1084,20 @@ BOOL CUnAlz::ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bHalt = bHalt;
|
m_bHalt = bHalt;
|
||||||
ret = TRUE;
|
|
||||||
|
if(m_nErr==ERR_NOERR) // 성공적으로 압축을 풀었다.. CRC 검사하기..
|
||||||
|
{
|
||||||
|
if(file.fileCRC==dwCRC32)
|
||||||
|
{
|
||||||
|
ret = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_nErr = ERR_INVALID_FILE_CRC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1065,14 +1111,16 @@ BOOL CUnAlz::ExtractRawfile(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
#define BZIP2_EXTRACT_BUF_SIZE 0x2000
|
#define BZIP2_EXTRACT_BUF_SIZE 0x2000
|
||||||
BOOL CUnAlz::ExtractBzip2(SExtractDest* dest, SLocalFileHeader& file)
|
BOOL CUnAlz::ExtractBzip2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
{
|
{
|
||||||
BZFILE *bzfp = NULL;
|
BZFILE *bzfp = NULL;
|
||||||
int smallMode = 0;
|
int smallMode = 0;
|
||||||
int verbosity = 1;
|
int verbosity = 1;
|
||||||
int bzerr;
|
int bzerr;
|
||||||
INT64 len;
|
INT64 len;
|
||||||
char buff[BZIP2_EXTRACT_BUF_SIZE];
|
BYTE buff[BZIP2_EXTRACT_BUF_SIZE];
|
||||||
INT64 nWritten = 0;
|
INT64 nWritten = 0;
|
||||||
BOOL bHalt = FALSE;
|
BOOL bHalt = FALSE;
|
||||||
|
UINT32 dwCRC32= 0;
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
FSeek(file.dwFileDataPos);
|
FSeek(file.dwFileDataPos);
|
||||||
|
|
||||||
|
@ -1080,11 +1128,15 @@ BOOL CUnAlz::ExtractBzip2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
|
|
||||||
if(bzfp==NULL){ASSERT(0); return FALSE;}
|
if(bzfp==NULL){ASSERT(0); return FALSE;}
|
||||||
|
|
||||||
|
m_nErr = ERR_NOERR;
|
||||||
while((len=BZ2_bzread(bzfp,buff,BZIP2_EXTRACT_BUF_SIZE))>0)
|
while((len=BZ2_bzread(bzfp,buff,BZIP2_EXTRACT_BUF_SIZE))>0)
|
||||||
{
|
{
|
||||||
WriteToDest(dest, (BYTE*)buff, (int)len);
|
WriteToDest(dest, (BYTE*)buff, (int)len);
|
||||||
//fwrite(buff,1,len,fp_w);
|
//fwrite(buff,1,len,fp_w);
|
||||||
|
|
||||||
|
dwCRC32 = crc32(dwCRC32,buff, (UINT)(len));
|
||||||
|
|
||||||
|
|
||||||
nWritten+=len;
|
nWritten+=len;
|
||||||
|
|
||||||
// progress callback
|
// progress callback
|
||||||
|
@ -1098,10 +1150,28 @@ BOOL CUnAlz::ExtractBzip2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(len<0) // 에러 상황..
|
||||||
|
{
|
||||||
|
m_nErr = ERR_INFLATE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
BZ2_bzReadClose( &bzerr, bzfp);
|
BZ2_bzReadClose( &bzerr, bzfp);
|
||||||
|
|
||||||
m_bHalt = bHalt;
|
m_bHalt = bHalt;
|
||||||
|
|
||||||
|
if(m_nErr==ERR_NOERR) // 성공적으로 압축을 풀었다.. CRC 검사하기..
|
||||||
|
{
|
||||||
|
if(file.fileCRC==dwCRC32)
|
||||||
|
{
|
||||||
|
ret = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_nErr = ERR_INVALID_FILE_CRC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// FILE* 를 사용할경우 사용하던 코드. - 멀티 볼륨 지원 안함..
|
// FILE* 를 사용할경우 사용하던 코드. - 멀티 볼륨 지원 안함..
|
||||||
BZFILE *bzfp = NULL;
|
BZFILE *bzfp = NULL;
|
||||||
|
@ -1140,7 +1210,7 @@ BOOL CUnAlz::ExtractBzip2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
m_bHalt = bHalt;
|
m_bHalt = bHalt;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return TRUE;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1188,6 +1258,7 @@ BOOL CUnAlz::ExtractDeflate2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
stream.next_out = pOutBuf;
|
stream.next_out = pOutBuf;
|
||||||
stream.avail_out = OUT_BUF_SIZE;
|
stream.avail_out = OUT_BUF_SIZE;
|
||||||
|
|
||||||
|
m_nErr = ERR_NOERR;
|
||||||
while(stream.avail_out>0)
|
while(stream.avail_out>0)
|
||||||
{
|
{
|
||||||
if(stream.avail_in==0 && nRestReadCompressed>0)
|
if(stream.avail_in==0 && nRestReadCompressed>0)
|
||||||
|
@ -1204,9 +1275,11 @@ BOOL CUnAlz::ExtractDeflate2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
m_nErr = ERR_CANT_READ_FILE;
|
m_nErr = ERR_CANT_READ_FILE;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(bIsEncrypted)
|
if(bIsEncrypted)
|
||||||
DecryptingData(uReadThis, pInBuf); // xf86
|
DecryptingData(uReadThis, pInBuf); // xf86
|
||||||
|
|
||||||
|
// dwCRC32 = crc32(dwCRC32,pInBuf, (UINT)(uReadThis));
|
||||||
|
|
||||||
nRestReadCompressed -= uReadThis;
|
nRestReadCompressed -= uReadThis;
|
||||||
stream.next_in = pInBuf;
|
stream.next_in = pInBuf;
|
||||||
|
@ -1245,6 +1318,7 @@ BOOL CUnAlz::ExtractDeflate2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
m_pFuncCallBack(NULL, nWritten, file.uncompressedSize, m_pCallbackParam, &bHalt);
|
m_pFuncCallBack(NULL, nWritten, file.uncompressedSize, m_pCallbackParam, &bHalt);
|
||||||
if(bHalt)
|
if(bHalt)
|
||||||
{
|
{
|
||||||
|
m_nErr = ERR_USER_ABORTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1258,10 +1332,21 @@ BOOL CUnAlz::ExtractDeflate2(SExtractDest* dest, SLocalFileHeader& file)
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_bHalt = bHalt;
|
m_bHalt = bHalt;
|
||||||
|
|
||||||
ret = TRUE;
|
|
||||||
|
if(m_nErr==ERR_NOERR) // 성공적으로 압축을 풀었다.. CRC 검사하기..
|
||||||
|
{
|
||||||
|
if(file.fileCRC==dwCRC32)
|
||||||
|
{
|
||||||
|
ret = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_nErr = ERR_INVALID_FILE_CRC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
END :
|
END :
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
|
@ -1497,17 +1582,16 @@ const char* CUnAlz::LastErrToStr(ERR nERR)
|
||||||
// by xf86
|
// by xf86
|
||||||
BOOL CUnAlz::chkValidPassword()
|
BOOL CUnAlz::chkValidPassword()
|
||||||
{
|
{
|
||||||
if(IsEncryptedFile())
|
if(IsEncryptedFile()==FALSE) {return TRUE;}
|
||||||
{
|
|
||||||
if (getPasswordLen() == 0){
|
if (getPasswordLen() == 0){
|
||||||
m_nErr = ERR_PASSWD_NOT_SET;
|
m_nErr = ERR_PASSWD_NOT_SET;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
InitCryptKeys(m_szPasswd);
|
InitCryptKeys(m_szPasswd);
|
||||||
if(CryptCheck(m_posCur->encChk) == FALSE){
|
if(CryptCheck(m_posCur->encChk) == FALSE){
|
||||||
m_nErr = ERR_INVALID_PASSWD;
|
m_nErr = ERR_INVALID_PASSWD;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -1638,21 +1722,25 @@ void CUnAlz::UpdateKeys(BYTE c)
|
||||||
/// @return
|
/// @return
|
||||||
/// @date 2004-11-27 오후 11:04:24
|
/// @date 2004-11-27 오후 11:04:24
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
BOOL CUnAlz::CryptCheck(BYTE* buf)
|
BOOL CUnAlz::CryptCheck(const BYTE* buf)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
BYTE c;
|
BYTE c;
|
||||||
|
BYTE temp[ENCR_HEADER_LEN];
|
||||||
|
|
||||||
|
memcpy(temp, buf, ENCR_HEADER_LEN); // 임시 복사.
|
||||||
|
|
||||||
for(i=0;i<ENCR_HEADER_LEN;i++)
|
for(i=0;i<ENCR_HEADER_LEN;i++)
|
||||||
{
|
{
|
||||||
c = buf[i] ^ DecryptByte();
|
c = temp[i] ^ DecryptByte();
|
||||||
UpdateKeys(c);
|
UpdateKeys(c);
|
||||||
buf[i] = c;
|
temp[i] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsDataDescr()) // Data descriptor present
|
if (IsDataDescr()) // Data descriptor present
|
||||||
return (m_posCur->head.fileTimeDate >> 8) == c;
|
return (m_posCur->head.fileTimeDate >> 8) == c;
|
||||||
else
|
else
|
||||||
return (m_posCur->passwordCRC) == c;
|
return ( ((m_posCur->fileCRC)>>24) ) == c; // 파일 crc 의 최상위 byte
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1701,3 +1789,5 @@ UINT32 CUnAlz::CRC32(UINT32 l, BYTE c)
|
||||||
const ULONG *CRC_TABLE = get_crc_table();
|
const ULONG *CRC_TABLE = get_crc_table();
|
||||||
return CRC_TABLE[(l ^ c) & 0xff] ^ (l >> 8);
|
return CRC_TABLE[(l ^ c) & 0xff] ^ (l >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
76
UnAlz.h
76
UnAlz.h
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
|
|
||||||
COPYRIGHT(C) 2004 hardkoder@gmail.com / http://www.kipple.pe.kr
|
COPYRIGHT(C) 2004-2005 hardkoder , http://www.kipple.pe.kr
|
||||||
|
|
||||||
저작권 정보 : ( BSD License )
|
저작권 정보 : ( BSD License )
|
||||||
- 이 소스는 자유로이 사용/수정/재배포 가능합니다.
|
- 이 소스는 자유로이 사용/수정/재배포 가능합니다.
|
||||||
|
@ -33,26 +33,39 @@
|
||||||
- 2GB 이상의 파일 처리 지원 (WINDOWS ONLY)
|
- 2GB 이상의 파일 처리 지원 (WINDOWS ONLY)
|
||||||
2004/10/22 - 다중 플랫폼(BSD/LINUX)지원을 위한 수정
|
2004/10/22 - 다중 플랫폼(BSD/LINUX)지원을 위한 수정
|
||||||
( BSD/LINUX 의 경우 2GB 이하의 파일만 지원 )
|
( BSD/LINUX 의 경우 2GB 이하의 파일만 지원 )
|
||||||
|
- unalz 0.20
|
||||||
2004/10/23 - by xxfree86 : DARWIN 컴파일 지원, 경로명에 "\\" 포함시 문제점 수정
|
2004/10/23 - by xxfree86 : DARWIN 컴파일 지원, 경로명에 "\\" 포함시 문제점 수정
|
||||||
2004/10/24 - by aqua0125 : 코드페이지 변환처리, 64bit 파일 처리
|
2004/10/24 - by aqua0125 : 코드페이지 변환처리, 64bit 파일 처리
|
||||||
- 빅엔디안, 코드페이지 변환 관련 소스 정리
|
- 빅엔디안, 코드페이지 변환 관련 소스 정리
|
||||||
2004/10/25 - by yongari : __LP64__ , 빅엔디안(le64toh/le132oh/le16toh) 관련 이슈 수정
|
2004/10/25 - by yongari : __LP64__ , 빅엔디안(le64toh/le132oh/le16toh) 관련 이슈 수정
|
||||||
2004/10/26 - BSD/LINUX : byte-order, libiconv 이슈 정리
|
2004/10/26 - BSD/LINUX : byte-order, libiconv 이슈 정리
|
||||||
|
- unalz 0.22
|
||||||
2004/10/30 - 정리 & 정리..
|
2004/10/30 - 정리 & 정리..
|
||||||
|
- unalz 0.23
|
||||||
2004/11/14 - by xxfre86 : 암호 걸린 파일 처리 추가
|
2004/11/14 - by xxfre86 : 암호 걸린 파일 처리 추가
|
||||||
|
- unalz 0.30
|
||||||
2004/11/27 - cygwin에서 컴파일 되도록 수정
|
2004/11/27 - cygwin에서 컴파일 되도록 수정
|
||||||
- 암호처리 부분에 일부 사용된 GPL 의 CZipArchive 코드를 "ZIP File Format Specification version 4.5" 문서를 참고해서 다시 코딩 & 정리
|
- 암호처리 부분에 일부 사용된 GPL 의 CZipArchive 코드를 "ZIP File Format Specification version 4.5" 문서를 참고해서 다시 코딩 & 정리
|
||||||
- 암호걸린 파일과 안걸린 파일 섞였을때 처리
|
- 암호걸린 파일과 안걸린 파일 섞였을때 처리
|
||||||
- 파일의 뒷부분이 잘려서 손상된 파일도 멀쩡한 부분까지는 압축을 풀도록 수정
|
- 파일의 뒷부분이 잘려서 손상된 파일도 멀쩡한 부분까지는 압축을 풀도록 수정
|
||||||
|
- unalz 0.31
|
||||||
|
2005/01/08 - 암호 잘못 입력시 한번 체크후 두번째는 정상 암호를 입력해서 풀지 못하게 되던 버그 수정
|
||||||
|
2005/02/05 - 압축 해제후 deflate 의 파일 CRC 확인 기능 추가
|
||||||
|
2005/03/07 - bzip2, raw 파일에 대한 파일 CRC 확인 기능 추가
|
||||||
|
2005/03/13 - ALZ 파일이 아닐경우 에러 코드(ERR_NOT_ALZ_FILE) 추가
|
||||||
|
2005/06/16 - GetFileList() 함수 버그 수정(리턴타입 변경)
|
||||||
|
2005/06/18 - by goweol : utf-8 사용시 파일이름에서 버퍼 오버플로우 발생하던 버그 수정
|
||||||
|
- unalz 0.4
|
||||||
|
|
||||||
|
|
||||||
할일 : ( * 표는 한거 )
|
기능 :
|
||||||
- bzip2 로 압축된 파일의 압축 해제 *
|
- alz 파일의 압축 해제 ( deflate/변형 bzip2/raw )
|
||||||
- UI 개선 ( PROGRESS, 에러 메시지 출력, 압축 해제 결과 ) *
|
- 분할 압축 파일 지원 (alz, a00, a01.. )
|
||||||
- 분할 압축 파일 지원 *
|
- 다양한 플래폼 지원 (Win32/POSIX(BSD/LINUX/DARWIN))
|
||||||
- 암호 걸린 파일 지원 *
|
- 암호걸린 파일의 압축 해제
|
||||||
- 손상된 파일에서의 좀더 많은 테스트 ->
|
- 뒷부분이 잘린 파일도 멀쩡한 부분까지 압축 해제 가능
|
||||||
- 파일 CRC 체크 -> alz 는 CRC 필드가 없다. OTL
|
- CRC 체크기능
|
||||||
|
|
||||||
|
|
||||||
컴파일 옵션 ( -DXXXX )
|
컴파일 옵션 ( -DXXXX )
|
||||||
- _WIN32 : WIN32
|
- _WIN32 : WIN32
|
||||||
|
@ -149,8 +162,8 @@ namespace UNALZ
|
||||||
# pragma pack(1)
|
# pragma pack(1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char UNALZ_VERSION[] = "CUnAlz0.31";
|
static const char UNALZ_VERSION[] = "CUnAlz0.4";
|
||||||
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004 hardkoder@gmail.com";
|
static const char UNALZ_COPYRIGHT[] = "Copyright(C) 2004-2005 by hardkoder ( http://www.kipple.pe.kr ) ";
|
||||||
|
|
||||||
enum {ENCR_HEADER_LEN=12}; // xf86
|
enum {ENCR_HEADER_LEN=12}; // xf86
|
||||||
// 맨 파일 앞..
|
// 맨 파일 앞..
|
||||||
|
@ -180,12 +193,20 @@ enum COMPRESSION_METHOD ///<
|
||||||
COMP_NOCOMP = 0,
|
COMP_NOCOMP = 0,
|
||||||
COMP_BZIP2 = 1,
|
COMP_BZIP2 = 1,
|
||||||
COMP_DEFLATE = 2,
|
COMP_DEFLATE = 2,
|
||||||
|
COMP_UNKNOWN = 3, // unknown!
|
||||||
|
};
|
||||||
|
|
||||||
|
enum FILE_ATTRIBUTE
|
||||||
|
{
|
||||||
|
FILEATTR_FILE = 0x1,
|
||||||
|
FILEATTR_FOLDER = 0x10,
|
||||||
|
FILEATTR_FILE2 = 0x20, /// FILEATTR_FILE 과 FILEATTR_FILE2 의 차이는 모르겠다..
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _SLocalFileHeaderHead ///< 고정 헤더.
|
struct _SLocalFileHeaderHead ///< 고정 헤더.
|
||||||
{
|
{
|
||||||
SHORT fileNameLength;
|
SHORT fileNameLength;
|
||||||
BYTE fileAttribute; // from http://www.zap.pe.kr
|
BYTE fileAttribute; // from http://www.zap.pe.kr, FILE_ATTRIBUE 참고
|
||||||
UINT32 fileTimeDate;
|
UINT32 fileTimeDate;
|
||||||
|
|
||||||
BYTE fileDescriptor; ///< 파일 크기 필드의 크기 : 0x10, 0x20, 0x40, 0x80 각각 1byte, 2byte, 4byte, 8byte.
|
BYTE fileDescriptor; ///< 파일 크기 필드의 크기 : 0x10, 0x20, 0x40, 0x80 각각 1byte, 2byte, 4byte, 8byte.
|
||||||
|
@ -206,12 +227,14 @@ struct _SLocalFileHeaderHead ///<
|
||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
struct _SDataDescriptor
|
struct _SDataDescriptor
|
||||||
{
|
{
|
||||||
UINT32 crc32;
|
UINT32 crc32;
|
||||||
UINT32 compressed;
|
UINT32 compressed;
|
||||||
UINT32 uncompressed;
|
UINT32 uncompressed;
|
||||||
};
|
};
|
||||||
|
*/
|
||||||
|
|
||||||
struct SLocalFileHeader
|
struct SLocalFileHeader
|
||||||
{
|
{
|
||||||
|
@ -221,16 +244,16 @@ struct SLocalFileHeader
|
||||||
_SLocalFileHeaderHead head;
|
_SLocalFileHeaderHead head;
|
||||||
|
|
||||||
BYTE compressionMethod; ///< 압축 방법 : 2 - deflate, 1 - 변형 bzip2, 0 - 압축 안함.
|
BYTE compressionMethod; ///< 압축 방법 : 2 - deflate, 1 - 변형 bzip2, 0 - 압축 안함.
|
||||||
BYTE unknown3[1]; ///< ???
|
BYTE unknown;
|
||||||
BYTE unknown4[3]; ///< 아마도 crc?
|
UINT32 fileCRC; ///< 파일의 CRC, 최상위 바이트는 암호 체크용으로도 사용된다.
|
||||||
BYTE passwordCRC; ///< 암호 체크를 위한 1byte crc
|
//BYTE passwordCRC; ///< 암호 체크를 위한 1byte crc
|
||||||
|
|
||||||
INT64 compressedSize;
|
INT64 compressedSize;
|
||||||
INT64 uncompressedSize;
|
INT64 uncompressedSize;
|
||||||
|
|
||||||
CHAR* fileName;
|
CHAR* fileName;
|
||||||
BYTE* extraField;
|
BYTE* extraField;
|
||||||
_SDataDescriptor dataDescriptor;
|
// _SDataDescriptor dataDescriptor;
|
||||||
INT64 dwFileDataPos; ///< file data 가 저장된 위치..
|
INT64 dwFileDataPos; ///< file data 가 저장된 위치..
|
||||||
|
|
||||||
BYTE encChk[ENCR_HEADER_LEN]; // xf86
|
BYTE encChk[ENCR_HEADER_LEN]; // xf86
|
||||||
|
@ -321,11 +344,12 @@ public:
|
||||||
void Close();
|
void Close();
|
||||||
BOOL SetCurrentFile(const char* szFileName);
|
BOOL SetCurrentFile(const char* szFileName);
|
||||||
BOOL ExtractCurrentFile(const char* szDestPathName, const char* szDestFileName=NULL);
|
BOOL ExtractCurrentFile(const char* szDestPathName, const char* szDestFileName=NULL);
|
||||||
BOOL ExtractCurrentFileToBuf(BYTE* pDestBuf, int nBufSize);
|
BOOL ExtractCurrentFileToBuf(BYTE* pDestBuf, int nBufSize); // pDestBuf=NULL 일 경우 테스트만 수행한다.
|
||||||
BOOL ExtractAll(const char* szDestPathName);
|
BOOL ExtractAll(const char* szDestPathName);
|
||||||
void SetCallback(_UnAlzCallback* pFunc, void* param=NULL);
|
void SetCallback(_UnAlzCallback* pFunc, void* param=NULL);
|
||||||
|
|
||||||
void setPassword(char *passwd) { if(strlen(passwd) == 0) return; strcpy(m_szPasswd, passwd); }; // xf86
|
void setPassword(char *passwd) { if(strlen(passwd) == 0) return; strcpy(m_szPasswd, passwd); }; // xf86
|
||||||
|
BOOL chkValidPassword(); // xf86
|
||||||
BOOL IsEncrypted() { return m_bIsEncrypted; };
|
BOOL IsEncrypted() { return m_bIsEncrypted; };
|
||||||
|
|
||||||
#ifdef _UNALZ_ICONV
|
#ifdef _UNALZ_ICONV
|
||||||
|
@ -346,10 +370,10 @@ public : ///< WIN32
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
public :
|
public :
|
||||||
typedef vector<SLocalFileHeader> FileList; ///< 파일 목록.
|
typedef vector<SLocalFileHeader> FileList; ///< 파일 목록.
|
||||||
const FileList& GetFileList() { return m_fileList; }; ///< file 목록 리턴
|
FileList* GetFileList() { return &m_fileList; }; ///< file 목록 리턴
|
||||||
FileList::iterator GetCurFileHeader() { return m_posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
|
void SetCurrentFile(FileList::iterator newPos); ///< low level 접근..
|
||||||
// const SLocalFileHeader* GetCurFileHeader() { return m_posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
|
FileList::iterator GetCurFileHeader() { return m_posCur; }; ///< 현재 (SetCurrentFile() 로 세팅된) 파일 정보
|
||||||
|
|
||||||
public :
|
public :
|
||||||
enum ERR ///< 에러 코드 - 정리 필요..
|
enum ERR ///< 에러 코드 - 정리 필요..
|
||||||
|
@ -357,6 +381,7 @@ public :
|
||||||
ERR_NOERR,
|
ERR_NOERR,
|
||||||
ERR_CANT_OPEN_FILE, ///< 파일 열기 실패
|
ERR_CANT_OPEN_FILE, ///< 파일 열기 실패
|
||||||
ERR_CORRUPTED_FILE, ///< 깨진 파일?
|
ERR_CORRUPTED_FILE, ///< 깨진 파일?
|
||||||
|
ERR_NOT_ALZ_FILE, ///< ALZ 파일이 아니다.
|
||||||
ERR_CANT_READ_SIG, ///< signature 읽기 실패
|
ERR_CANT_READ_SIG, ///< signature 읽기 실패
|
||||||
ERR_CANT_READ_FILE,
|
ERR_CANT_READ_FILE,
|
||||||
|
|
||||||
|
@ -371,6 +396,9 @@ public :
|
||||||
ERR_MEM_ALLOC_FAILED,
|
ERR_MEM_ALLOC_FAILED,
|
||||||
ERR_FILE_READ_ERROR,
|
ERR_FILE_READ_ERROR,
|
||||||
ERR_INFLATE_FAILED,
|
ERR_INFLATE_FAILED,
|
||||||
|
ERR_BZIP2_FAILED,
|
||||||
|
ERR_INVALID_FILE_CRC,
|
||||||
|
ERR_UNKNOWN_COMPRESSION_METHOD,
|
||||||
|
|
||||||
ERR_ICONV_CANT_OPEN,
|
ERR_ICONV_CANT_OPEN,
|
||||||
ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS,
|
ERR_ICONV_INVALID_MULTISEQUENCE_OF_CHARACTERS,
|
||||||
|
@ -474,11 +502,10 @@ private : //
|
||||||
|
|
||||||
BOOL m_bIsEncrypted; // xf86
|
BOOL m_bIsEncrypted; // xf86
|
||||||
BOOL m_bIsDataDescr;
|
BOOL m_bIsDataDescr;
|
||||||
char m_szPasswd[256];
|
char m_szPasswd[512];
|
||||||
UINT32 m_keys[3];
|
|
||||||
|
|
||||||
private :
|
private :
|
||||||
/*
|
/* from CZipArchive
|
||||||
void CryptDecodeBuffer(UINT32 uCount, CHAR *buf);
|
void CryptDecodeBuffer(UINT32 uCount, CHAR *buf);
|
||||||
void CryptInitKeys();
|
void CryptInitKeys();
|
||||||
void CryptUpdateKeys(CHAR c);
|
void CryptUpdateKeys(CHAR c);
|
||||||
|
@ -489,12 +516,11 @@ private :
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private : // encryption 처리
|
private : // encryption 처리
|
||||||
BOOL chkValidPassword(); // xf86
|
|
||||||
BOOL IsEncryptedFile(BYTE fileDescriptor);
|
BOOL IsEncryptedFile(BYTE fileDescriptor);
|
||||||
BOOL IsEncryptedFile();
|
BOOL IsEncryptedFile();
|
||||||
void InitCryptKeys(const CHAR* szPassword);
|
void InitCryptKeys(const CHAR* szPassword);
|
||||||
void UpdateKeys(BYTE c);
|
void UpdateKeys(BYTE c);
|
||||||
BOOL CryptCheck(BYTE* buf);
|
BOOL CryptCheck(const BYTE* buf);
|
||||||
BYTE DecryptByte();
|
BYTE DecryptByte();
|
||||||
void DecryptingData(int nSize, BYTE* data);
|
void DecryptingData(int nSize, BYTE* data);
|
||||||
UINT32 CRC32(UINT32 l, BYTE c);
|
UINT32 CRC32(UINT32 l, BYTE c);
|
||||||
|
|
5
main.cpp
5
main.cpp
|
@ -71,8 +71,9 @@ int main(int argc, char* argv[])
|
||||||
// printf("unalz v0.20 (2004/10/22) \n");
|
// printf("unalz v0.20 (2004/10/22) \n");
|
||||||
// printf("unalz v0.22 (2004/10/27) \n");
|
// printf("unalz v0.22 (2004/10/27) \n");
|
||||||
// printf("unalz v0.23 (2004/10/30) \n");
|
// printf("unalz v0.23 (2004/10/30) \n");
|
||||||
printf("unalz v0.31 (2004/11/27) \n");
|
// printf("unalz v0.31 (2004/11/27) \n");
|
||||||
printf("Copyright(C) 2004 koder (http://www.kipple.pe.kr) \n");
|
printf("unalz v0.4 (2005/06/18) \n");
|
||||||
|
printf("Copyright(C) 2004-2005 by hardkoder (http://www.kipple.pe.kr) \n");
|
||||||
|
|
||||||
if(argc<2)
|
if(argc<2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -179,10 +179,6 @@ SOURCE=.\zlib\zconf.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\zlib\zconf.in.h
|
|
||||||
# End Source File
|
|
||||||
# Begin Source File
|
|
||||||
|
|
||||||
SOURCE=.\zlib\zlib.h
|
SOURCE=.\zlib\zlib.h
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
644
zlib/crc32.c
644
zlib/crc32.c
|
@ -1,311 +1,333 @@
|
||||||
/* crc32.c -- compute the CRC-32 of a data stream
|
/* crc32.c -- compute the CRC-32 of a data stream
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2003 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*
|
*
|
||||||
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
* Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
|
||||||
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
* CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
|
||||||
* tables for updating the shift register in one step with three exclusive-ors
|
* tables for updating the shift register in one step with three exclusive-ors
|
||||||
* instead of four steps with four exclusive-ors. This results about a factor
|
* instead of four steps with four exclusive-ors. This results about a factor
|
||||||
* of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
* of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
#ifdef MAKECRCH
|
/*
|
||||||
# include <stdio.h>
|
Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
|
||||||
# ifndef DYNAMIC_CRC_TABLE
|
protection on the static variables used to control the first-use generation
|
||||||
# define DYNAMIC_CRC_TABLE
|
of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
|
||||||
# endif /* !DYNAMIC_CRC_TABLE */
|
first call get_crc_table() to initialize the tables before allowing more than
|
||||||
#endif /* MAKECRCH */
|
one thread to use crc32().
|
||||||
|
*/
|
||||||
#include "zutil.h" /* for STDC and FAR definitions */
|
|
||||||
|
#ifdef MAKECRCH
|
||||||
#define local static
|
# include <stdio.h>
|
||||||
|
# ifndef DYNAMIC_CRC_TABLE
|
||||||
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
# define DYNAMIC_CRC_TABLE
|
||||||
#ifndef NOBYFOUR
|
# endif /* !DYNAMIC_CRC_TABLE */
|
||||||
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
#endif /* MAKECRCH */
|
||||||
# include <limits.h>
|
|
||||||
# define BYFOUR
|
#include "zutil.h" /* for STDC and FAR definitions */
|
||||||
# if (UINT_MAX == 0xffffffffUL)
|
|
||||||
typedef unsigned int u4;
|
#define local static
|
||||||
# else
|
|
||||||
# if (ULONG_MAX == 0xffffffffUL)
|
/* Find a four-byte integer type for crc32_little() and crc32_big(). */
|
||||||
typedef unsigned long u4;
|
#ifndef NOBYFOUR
|
||||||
# else
|
# ifdef STDC /* need ANSI C limits.h to determine sizes */
|
||||||
# if (USHRT_MAX == 0xffffffffUL)
|
# include <limits.h>
|
||||||
typedef unsigned short u4;
|
# define BYFOUR
|
||||||
# else
|
# if (UINT_MAX == 0xffffffffUL)
|
||||||
# undef BYFOUR /* can't find a four-byte integer type! */
|
typedef unsigned int u4;
|
||||||
# endif
|
# else
|
||||||
# endif
|
# if (ULONG_MAX == 0xffffffffUL)
|
||||||
# endif
|
typedef unsigned long u4;
|
||||||
# endif /* STDC */
|
# else
|
||||||
#endif /* !NOBYFOUR */
|
# if (USHRT_MAX == 0xffffffffUL)
|
||||||
|
typedef unsigned short u4;
|
||||||
/* Definitions for doing the crc four data bytes at a time. */
|
# else
|
||||||
#ifdef BYFOUR
|
# undef BYFOUR /* can't find a four-byte integer type! */
|
||||||
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
|
# endif
|
||||||
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
# endif
|
||||||
local unsigned long crc32_little OF((unsigned long,
|
# endif
|
||||||
const unsigned char FAR *, unsigned));
|
# endif /* STDC */
|
||||||
local unsigned long crc32_big OF((unsigned long,
|
#endif /* !NOBYFOUR */
|
||||||
const unsigned char FAR *, unsigned));
|
|
||||||
# define TBLS 8
|
/* Definitions for doing the crc four data bytes at a time. */
|
||||||
#else
|
#ifdef BYFOUR
|
||||||
# define TBLS 1
|
# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
|
||||||
#endif /* BYFOUR */
|
(((w)&0xff00)<<8)+(((w)&0xff)<<24))
|
||||||
|
local unsigned long crc32_little OF((unsigned long,
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
const unsigned char FAR *, unsigned));
|
||||||
|
local unsigned long crc32_big OF((unsigned long,
|
||||||
local int crc_table_empty = 1;
|
const unsigned char FAR *, unsigned));
|
||||||
local unsigned long FAR crc_table[TBLS][256];
|
# define TBLS 8
|
||||||
local void make_crc_table OF((void));
|
#else
|
||||||
#ifdef MAKECRCH
|
# define TBLS 1
|
||||||
local void write_table OF((FILE *, const unsigned long FAR *));
|
#endif /* BYFOUR */
|
||||||
#endif /* MAKECRCH */
|
|
||||||
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
/*
|
|
||||||
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
local volatile int crc_table_empty = 1;
|
||||||
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
local unsigned long FAR crc_table[TBLS][256];
|
||||||
|
local void make_crc_table OF((void));
|
||||||
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
#ifdef MAKECRCH
|
||||||
with the lowest powers in the most significant bit. Then adding polynomials
|
local void write_table OF((FILE *, const unsigned long FAR *));
|
||||||
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
#endif /* MAKECRCH */
|
||||||
one. If we call the above polynomial p, and represent a byte as the
|
|
||||||
polynomial q, also with the lowest power in the most significant bit (so the
|
/*
|
||||||
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
|
||||||
where a mod b means the remainder after dividing a by b.
|
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
|
||||||
|
|
||||||
This calculation is done using the shift-register method of multiplying and
|
Polynomials over GF(2) are represented in binary, one bit per coefficient,
|
||||||
taking the remainder. The register is initialized to zero, and for each
|
with the lowest powers in the most significant bit. Then adding polynomials
|
||||||
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
is just exclusive-or, and multiplying a polynomial by x is a right shift by
|
||||||
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
one. If we call the above polynomial p, and represent a byte as the
|
||||||
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
polynomial q, also with the lowest power in the most significant bit (so the
|
||||||
out is a one). We start with the highest power (least significant bit) of
|
byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
|
||||||
q and repeat for all eight bits of q.
|
where a mod b means the remainder after dividing a by b.
|
||||||
|
|
||||||
The first table is simply the CRC of all possible eight bit values. This is
|
This calculation is done using the shift-register method of multiplying and
|
||||||
all the information needed to generate CRCs on data a byte at a time for all
|
taking the remainder. The register is initialized to zero, and for each
|
||||||
combinations of CRC register values and incoming bytes. The remaining tables
|
incoming bit, x^32 is added mod p to the register if the bit is a one (where
|
||||||
allow for word-at-a-time CRC calculation for both big-endian and little-
|
x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
|
||||||
endian machines, where a word is four bytes.
|
x (which is shifting right by one and adding x^32 mod p if the bit shifted
|
||||||
*/
|
out is a one). We start with the highest power (least significant bit) of
|
||||||
local void make_crc_table()
|
q and repeat for all eight bits of q.
|
||||||
{
|
|
||||||
unsigned long c;
|
The first table is simply the CRC of all possible eight bit values. This is
|
||||||
int n, k;
|
all the information needed to generate CRCs on data a byte at a time for all
|
||||||
unsigned long poly; /* polynomial exclusive-or pattern */
|
combinations of CRC register values and incoming bytes. The remaining tables
|
||||||
/* terms of polynomial defining this crc (except x^32): */
|
allow for word-at-a-time CRC calculation for both big-endian and little-
|
||||||
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
endian machines, where a word is four bytes.
|
||||||
|
*/
|
||||||
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
local void make_crc_table()
|
||||||
poly = 0UL;
|
{
|
||||||
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
unsigned long c;
|
||||||
poly |= 1UL << (31 - p[n]);
|
int n, k;
|
||||||
|
unsigned long poly; /* polynomial exclusive-or pattern */
|
||||||
/* generate a crc for every 8-bit value */
|
/* terms of polynomial defining this crc (except x^32): */
|
||||||
for (n = 0; n < 256; n++) {
|
static volatile int first = 1; /* flag to limit concurrent making */
|
||||||
c = (unsigned long)n;
|
static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
|
||||||
for (k = 0; k < 8; k++)
|
|
||||||
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
/* See if another task is already doing this (not thread-safe, but better
|
||||||
crc_table[0][n] = c;
|
than nothing -- significantly reduces duration of vulnerability in
|
||||||
}
|
case the advice about DYNAMIC_CRC_TABLE is ignored) */
|
||||||
|
if (first) {
|
||||||
#ifdef BYFOUR
|
first = 0;
|
||||||
/* generate crc for each value followed by one, two, and three zeros, and
|
|
||||||
then the byte reversal of those as well as the first table */
|
/* make exclusive-or pattern from polynomial (0xedb88320UL) */
|
||||||
for (n = 0; n < 256; n++) {
|
poly = 0UL;
|
||||||
c = crc_table[0][n];
|
for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
|
||||||
crc_table[4][n] = REV(c);
|
poly |= 1UL << (31 - p[n]);
|
||||||
for (k = 1; k < 4; k++) {
|
|
||||||
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
/* generate a crc for every 8-bit value */
|
||||||
crc_table[k][n] = c;
|
for (n = 0; n < 256; n++) {
|
||||||
crc_table[k + 4][n] = REV(c);
|
c = (unsigned long)n;
|
||||||
}
|
for (k = 0; k < 8; k++)
|
||||||
}
|
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
|
||||||
#endif /* BYFOUR */
|
crc_table[0][n] = c;
|
||||||
|
}
|
||||||
crc_table_empty = 0;
|
|
||||||
|
#ifdef BYFOUR
|
||||||
#ifdef MAKECRCH
|
/* generate crc for each value followed by one, two, and three zeros,
|
||||||
/* write out CRC tables to crc32.h */
|
and then the byte reversal of those as well as the first table */
|
||||||
{
|
for (n = 0; n < 256; n++) {
|
||||||
FILE *out;
|
c = crc_table[0][n];
|
||||||
|
crc_table[4][n] = REV(c);
|
||||||
out = fopen("crc32.h", "w");
|
for (k = 1; k < 4; k++) {
|
||||||
if (out == NULL) return;
|
c = crc_table[0][c & 0xff] ^ (c >> 8);
|
||||||
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
crc_table[k][n] = c;
|
||||||
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
crc_table[k + 4][n] = REV(c);
|
||||||
fprintf(out, "local const unsigned long FAR ");
|
}
|
||||||
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
}
|
||||||
write_table(out, crc_table[0]);
|
#endif /* BYFOUR */
|
||||||
# ifdef BYFOUR
|
|
||||||
fprintf(out, "#ifdef BYFOUR\n");
|
crc_table_empty = 0;
|
||||||
for (k = 1; k < 8; k++) {
|
}
|
||||||
fprintf(out, " },\n {\n");
|
else { /* not first */
|
||||||
write_table(out, crc_table[k]);
|
/* wait for the other guy to finish (not efficient, but rare) */
|
||||||
}
|
while (crc_table_empty)
|
||||||
fprintf(out, "#endif\n");
|
;
|
||||||
# endif /* BYFOUR */
|
}
|
||||||
fprintf(out, " }\n};\n");
|
|
||||||
fclose(out);
|
#ifdef MAKECRCH
|
||||||
}
|
/* write out CRC tables to crc32.h */
|
||||||
#endif /* MAKECRCH */
|
{
|
||||||
}
|
FILE *out;
|
||||||
|
|
||||||
#ifdef MAKECRCH
|
out = fopen("crc32.h", "w");
|
||||||
local void write_table(out, table)
|
if (out == NULL) return;
|
||||||
FILE *out;
|
fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
|
||||||
const unsigned long FAR *table;
|
fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
|
||||||
{
|
fprintf(out, "local const unsigned long FAR ");
|
||||||
int n;
|
fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
|
||||||
|
write_table(out, crc_table[0]);
|
||||||
for (n = 0; n < 256; n++)
|
# ifdef BYFOUR
|
||||||
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
fprintf(out, "#ifdef BYFOUR\n");
|
||||||
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
for (k = 1; k < 8; k++) {
|
||||||
}
|
fprintf(out, " },\n {\n");
|
||||||
#endif /* MAKECRCH */
|
write_table(out, crc_table[k]);
|
||||||
|
}
|
||||||
#else /* !DYNAMIC_CRC_TABLE */
|
fprintf(out, "#endif\n");
|
||||||
/* ========================================================================
|
# endif /* BYFOUR */
|
||||||
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
|
fprintf(out, " }\n};\n");
|
||||||
*/
|
fclose(out);
|
||||||
#include "crc32.h"
|
}
|
||||||
#endif /* DYNAMIC_CRC_TABLE */
|
#endif /* MAKECRCH */
|
||||||
|
}
|
||||||
/* =========================================================================
|
|
||||||
* This function can be used by asm versions of crc32()
|
#ifdef MAKECRCH
|
||||||
*/
|
local void write_table(out, table)
|
||||||
const unsigned long FAR * ZEXPORT get_crc_table()
|
FILE *out;
|
||||||
{
|
const unsigned long FAR *table;
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
{
|
||||||
if (crc_table_empty) make_crc_table();
|
int n;
|
||||||
#endif /* DYNAMIC_CRC_TABLE */
|
|
||||||
return (const unsigned long FAR *)crc_table;
|
for (n = 0; n < 256; n++)
|
||||||
}
|
fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
|
||||||
|
n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
|
||||||
/* ========================================================================= */
|
}
|
||||||
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
|
#endif /* MAKECRCH */
|
||||||
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
|
||||||
|
#else /* !DYNAMIC_CRC_TABLE */
|
||||||
/* ========================================================================= */
|
/* ========================================================================
|
||||||
unsigned long ZEXPORT crc32(crc, buf, len)
|
* Tables of CRC-32s of all single-byte values, made by make_crc_table().
|
||||||
unsigned long crc;
|
*/
|
||||||
const unsigned char FAR *buf;
|
#include "crc32.h"
|
||||||
unsigned len;
|
#endif /* DYNAMIC_CRC_TABLE */
|
||||||
{
|
|
||||||
if (buf == Z_NULL) return 0UL;
|
/* =========================================================================
|
||||||
|
* This function can be used by asm versions of crc32()
|
||||||
#ifdef DYNAMIC_CRC_TABLE
|
*/
|
||||||
if (crc_table_empty)
|
const unsigned long FAR * ZEXPORT get_crc_table()
|
||||||
make_crc_table();
|
{
|
||||||
#endif /* DYNAMIC_CRC_TABLE */
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
|
if (crc_table_empty)
|
||||||
#ifdef BYFOUR
|
make_crc_table();
|
||||||
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
#endif /* DYNAMIC_CRC_TABLE */
|
||||||
u4 endian;
|
return (const unsigned long FAR *)crc_table;
|
||||||
|
}
|
||||||
endian = 1;
|
|
||||||
if (*((unsigned char *)(&endian)))
|
/* ========================================================================= */
|
||||||
return crc32_little(crc, buf, len);
|
#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
|
||||||
else
|
#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
|
||||||
return crc32_big(crc, buf, len);
|
|
||||||
}
|
/* ========================================================================= */
|
||||||
#endif /* BYFOUR */
|
unsigned long ZEXPORT crc32(crc, buf, len)
|
||||||
crc = crc ^ 0xffffffffUL;
|
unsigned long crc;
|
||||||
while (len >= 8) {
|
const unsigned char FAR *buf;
|
||||||
DO8;
|
unsigned len;
|
||||||
len -= 8;
|
{
|
||||||
}
|
if (buf == Z_NULL) return 0UL;
|
||||||
if (len) do {
|
|
||||||
DO1;
|
#ifdef DYNAMIC_CRC_TABLE
|
||||||
} while (--len);
|
if (crc_table_empty)
|
||||||
return crc ^ 0xffffffffUL;
|
make_crc_table();
|
||||||
}
|
#endif /* DYNAMIC_CRC_TABLE */
|
||||||
|
|
||||||
#ifdef BYFOUR
|
#ifdef BYFOUR
|
||||||
|
if (sizeof(void *) == sizeof(ptrdiff_t)) {
|
||||||
/* ========================================================================= */
|
u4 endian;
|
||||||
#define DOLIT4 c ^= *buf4++; \
|
|
||||||
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
|
endian = 1;
|
||||||
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
|
if (*((unsigned char *)(&endian)))
|
||||||
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
|
return crc32_little(crc, buf, len);
|
||||||
|
else
|
||||||
/* ========================================================================= */
|
return crc32_big(crc, buf, len);
|
||||||
local unsigned long crc32_little(crc, buf, len)
|
}
|
||||||
unsigned long crc;
|
#endif /* BYFOUR */
|
||||||
const unsigned char FAR *buf;
|
crc = crc ^ 0xffffffffUL;
|
||||||
unsigned len;
|
while (len >= 8) {
|
||||||
{
|
DO8;
|
||||||
register u4 c;
|
len -= 8;
|
||||||
register const u4 FAR *buf4;
|
}
|
||||||
|
if (len) do {
|
||||||
c = (u4)crc;
|
DO1;
|
||||||
c = ~c;
|
} while (--len);
|
||||||
while (len && ((ptrdiff_t)buf & 3)) {
|
return crc ^ 0xffffffffUL;
|
||||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
}
|
||||||
len--;
|
|
||||||
}
|
#ifdef BYFOUR
|
||||||
|
|
||||||
buf4 = (const u4 FAR *)buf;
|
/* ========================================================================= */
|
||||||
while (len >= 32) {
|
#define DOLIT4 c ^= *buf4++; \
|
||||||
DOLIT32;
|
c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
|
||||||
len -= 32;
|
crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
|
||||||
}
|
#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
|
||||||
while (len >= 4) {
|
|
||||||
DOLIT4;
|
/* ========================================================================= */
|
||||||
len -= 4;
|
local unsigned long crc32_little(crc, buf, len)
|
||||||
}
|
unsigned long crc;
|
||||||
buf = (const unsigned char FAR *)buf4;
|
const unsigned char FAR *buf;
|
||||||
|
unsigned len;
|
||||||
if (len) do {
|
{
|
||||||
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
register u4 c;
|
||||||
} while (--len);
|
register const u4 FAR *buf4;
|
||||||
c = ~c;
|
|
||||||
return (unsigned long)c;
|
c = (u4)crc;
|
||||||
}
|
c = ~c;
|
||||||
|
while (len && ((ptrdiff_t)buf & 3)) {
|
||||||
/* ========================================================================= */
|
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||||
#define DOBIG4 c ^= *++buf4; \
|
len--;
|
||||||
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
|
}
|
||||||
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
|
|
||||||
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
|
buf4 = (const u4 FAR *)buf;
|
||||||
|
while (len >= 32) {
|
||||||
/* ========================================================================= */
|
DOLIT32;
|
||||||
local unsigned long crc32_big(crc, buf, len)
|
len -= 32;
|
||||||
unsigned long crc;
|
}
|
||||||
const unsigned char FAR *buf;
|
while (len >= 4) {
|
||||||
unsigned len;
|
DOLIT4;
|
||||||
{
|
len -= 4;
|
||||||
register u4 c;
|
}
|
||||||
register const u4 FAR *buf4;
|
buf = (const unsigned char FAR *)buf4;
|
||||||
|
|
||||||
c = REV((u4)crc);
|
if (len) do {
|
||||||
c = ~c;
|
c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
|
||||||
while (len && ((ptrdiff_t)buf & 3)) {
|
} while (--len);
|
||||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
c = ~c;
|
||||||
len--;
|
return (unsigned long)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf4 = (const u4 FAR *)buf;
|
/* ========================================================================= */
|
||||||
buf4--;
|
#define DOBIG4 c ^= *++buf4; \
|
||||||
while (len >= 32) {
|
c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
|
||||||
DOBIG32;
|
crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
|
||||||
len -= 32;
|
#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
|
||||||
}
|
|
||||||
while (len >= 4) {
|
/* ========================================================================= */
|
||||||
DOBIG4;
|
local unsigned long crc32_big(crc, buf, len)
|
||||||
len -= 4;
|
unsigned long crc;
|
||||||
}
|
const unsigned char FAR *buf;
|
||||||
buf4++;
|
unsigned len;
|
||||||
buf = (const unsigned char FAR *)buf4;
|
{
|
||||||
|
register u4 c;
|
||||||
if (len) do {
|
register const u4 FAR *buf4;
|
||||||
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
|
||||||
} while (--len);
|
c = REV((u4)crc);
|
||||||
c = ~c;
|
c = ~c;
|
||||||
return (unsigned long)(REV(c));
|
while (len && ((ptrdiff_t)buf & 3)) {
|
||||||
}
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||||
|
len--;
|
||||||
#endif /* BYFOUR */
|
}
|
||||||
|
|
||||||
|
buf4 = (const u4 FAR *)buf;
|
||||||
|
buf4--;
|
||||||
|
while (len >= 32) {
|
||||||
|
DOBIG32;
|
||||||
|
len -= 32;
|
||||||
|
}
|
||||||
|
while (len >= 4) {
|
||||||
|
DOBIG4;
|
||||||
|
len -= 4;
|
||||||
|
}
|
||||||
|
buf4++;
|
||||||
|
buf = (const unsigned char FAR *)buf4;
|
||||||
|
|
||||||
|
if (len) do {
|
||||||
|
c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
|
||||||
|
} while (--len);
|
||||||
|
c = ~c;
|
||||||
|
return (unsigned long)(REV(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* BYFOUR */
|
||||||
|
|
1241
zlib/infback.c
1241
zlib/infback.c
File diff suppressed because it is too large
Load diff
610
zlib/inffast.c
610
zlib/inffast.c
|
@ -1,305 +1,305 @@
|
||||||
/* inffast.c -- fast decoding
|
/* inffast.c -- fast decoding
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2004 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "zutil.h"
|
#include "zutil.h"
|
||||||
#include "inftrees.h"
|
#include "inftrees.h"
|
||||||
#include "inflate.h"
|
#include "inflate.h"
|
||||||
#include "inffast.h"
|
#include "inffast.h"
|
||||||
|
|
||||||
#ifndef ASMINF
|
#ifndef ASMINF
|
||||||
|
|
||||||
/* Allow machine dependent optimization for post-increment or pre-increment.
|
/* Allow machine dependent optimization for post-increment or pre-increment.
|
||||||
Based on testing to date,
|
Based on testing to date,
|
||||||
Pre-increment preferred for:
|
Pre-increment preferred for:
|
||||||
- PowerPC G3 (Adler)
|
- PowerPC G3 (Adler)
|
||||||
- MIPS R5000 (Randers-Pehrson)
|
- MIPS R5000 (Randers-Pehrson)
|
||||||
Post-increment preferred for:
|
Post-increment preferred for:
|
||||||
- none
|
- none
|
||||||
No measurable difference:
|
No measurable difference:
|
||||||
- Pentium III (Anderson)
|
- Pentium III (Anderson)
|
||||||
- 68060 (Nikl)
|
- M68060 (Nikl)
|
||||||
*/
|
*/
|
||||||
#ifdef POSTINC
|
#ifdef POSTINC
|
||||||
# define OFF 0
|
# define OFF 0
|
||||||
# define PUP(a) *(a)++
|
# define PUP(a) *(a)++
|
||||||
#else
|
#else
|
||||||
# define OFF 1
|
# define OFF 1
|
||||||
# define PUP(a) *++(a)
|
# define PUP(a) *++(a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Decode literal, length, and distance codes and write out the resulting
|
Decode literal, length, and distance codes and write out the resulting
|
||||||
literal and match bytes until either not enough input or output is
|
literal and match bytes until either not enough input or output is
|
||||||
available, an end-of-block is encountered, or a data error is encountered.
|
available, an end-of-block is encountered, or a data error is encountered.
|
||||||
When large enough input and output buffers are supplied to inflate(), for
|
When large enough input and output buffers are supplied to inflate(), for
|
||||||
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
example, a 16K input buffer and a 64K output buffer, more than 95% of the
|
||||||
inflate execution time is spent in this routine.
|
inflate execution time is spent in this routine.
|
||||||
|
|
||||||
Entry assumptions:
|
Entry assumptions:
|
||||||
|
|
||||||
state->mode == LEN
|
state->mode == LEN
|
||||||
strm->avail_in >= 6
|
strm->avail_in >= 6
|
||||||
strm->avail_out >= 258
|
strm->avail_out >= 258
|
||||||
start >= strm->avail_out
|
start >= strm->avail_out
|
||||||
state->bits < 8
|
state->bits < 8
|
||||||
|
|
||||||
On return, state->mode is one of:
|
On return, state->mode is one of:
|
||||||
|
|
||||||
LEN -- ran out of enough output space or enough available input
|
LEN -- ran out of enough output space or enough available input
|
||||||
TYPE -- reached end of block code, inflate() to interpret next block
|
TYPE -- reached end of block code, inflate() to interpret next block
|
||||||
BAD -- error in block data
|
BAD -- error in block data
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- The maximum input bits used by a length/distance pair is 15 bits for the
|
- The maximum input bits used by a length/distance pair is 15 bits for the
|
||||||
length code, 5 bits for the length extra, 15 bits for the distance code,
|
length code, 5 bits for the length extra, 15 bits for the distance code,
|
||||||
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
and 13 bits for the distance extra. This totals 48 bits, or six bytes.
|
||||||
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
Therefore if strm->avail_in >= 6, then there is enough input to avoid
|
||||||
checking for available input while decoding.
|
checking for available input while decoding.
|
||||||
|
|
||||||
- The maximum bytes that a single length/distance pair can output is 258
|
- The maximum bytes that a single length/distance pair can output is 258
|
||||||
bytes, which is the maximum length that can be coded. inflate_fast()
|
bytes, which is the maximum length that can be coded. inflate_fast()
|
||||||
requires strm->avail_out >= 258 for each loop to avoid checking for
|
requires strm->avail_out >= 258 for each loop to avoid checking for
|
||||||
output space.
|
output space.
|
||||||
*/
|
*/
|
||||||
void inflate_fast(strm, start)
|
void inflate_fast(strm, start)
|
||||||
z_streamp strm;
|
z_streamp strm;
|
||||||
unsigned start; /* inflate()'s starting value for strm->avail_out */
|
unsigned start; /* inflate()'s starting value for strm->avail_out */
|
||||||
{
|
{
|
||||||
struct inflate_state FAR *state;
|
struct inflate_state FAR *state;
|
||||||
unsigned char FAR *in; /* local strm->next_in */
|
unsigned char FAR *in; /* local strm->next_in */
|
||||||
unsigned char FAR *last; /* while in < last, enough input available */
|
unsigned char FAR *last; /* while in < last, enough input available */
|
||||||
unsigned char FAR *out; /* local strm->next_out */
|
unsigned char FAR *out; /* local strm->next_out */
|
||||||
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
|
||||||
unsigned char FAR *end; /* while out < end, enough space available */
|
unsigned char FAR *end; /* while out < end, enough space available */
|
||||||
unsigned wsize; /* window size or zero if not using window */
|
unsigned wsize; /* window size or zero if not using window */
|
||||||
unsigned whave; /* valid bytes in the window */
|
unsigned whave; /* valid bytes in the window */
|
||||||
unsigned write; /* window write index */
|
unsigned write; /* window write index */
|
||||||
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
|
||||||
unsigned long hold; /* local strm->hold */
|
unsigned long hold; /* local strm->hold */
|
||||||
unsigned bits; /* local strm->bits */
|
unsigned bits; /* local strm->bits */
|
||||||
code const FAR *lcode; /* local strm->lencode */
|
code const FAR *lcode; /* local strm->lencode */
|
||||||
code const FAR *dcode; /* local strm->distcode */
|
code const FAR *dcode; /* local strm->distcode */
|
||||||
unsigned lmask; /* mask for first level of length codes */
|
unsigned lmask; /* mask for first level of length codes */
|
||||||
unsigned dmask; /* mask for first level of distance codes */
|
unsigned dmask; /* mask for first level of distance codes */
|
||||||
code this; /* retrieved table entry */
|
code this; /* retrieved table entry */
|
||||||
unsigned op; /* code bits, operation, extra bits, or */
|
unsigned op; /* code bits, operation, extra bits, or */
|
||||||
/* window position, window bytes to copy */
|
/* window position, window bytes to copy */
|
||||||
unsigned len; /* match length, unused bytes */
|
unsigned len; /* match length, unused bytes */
|
||||||
unsigned dist; /* match distance */
|
unsigned dist; /* match distance */
|
||||||
unsigned char FAR *from; /* where to copy match from */
|
unsigned char FAR *from; /* where to copy match from */
|
||||||
|
|
||||||
/* copy state to local variables */
|
/* copy state to local variables */
|
||||||
state = (struct inflate_state FAR *)strm->state;
|
state = (struct inflate_state FAR *)strm->state;
|
||||||
in = strm->next_in - OFF;
|
in = strm->next_in - OFF;
|
||||||
last = in + (strm->avail_in - 5);
|
last = in + (strm->avail_in - 5);
|
||||||
out = strm->next_out - OFF;
|
out = strm->next_out - OFF;
|
||||||
beg = out - (start - strm->avail_out);
|
beg = out - (start - strm->avail_out);
|
||||||
end = out + (strm->avail_out - 257);
|
end = out + (strm->avail_out - 257);
|
||||||
wsize = state->wsize;
|
wsize = state->wsize;
|
||||||
whave = state->whave;
|
whave = state->whave;
|
||||||
write = state->write;
|
write = state->write;
|
||||||
window = state->window;
|
window = state->window;
|
||||||
hold = state->hold;
|
hold = state->hold;
|
||||||
bits = state->bits;
|
bits = state->bits;
|
||||||
lcode = state->lencode;
|
lcode = state->lencode;
|
||||||
dcode = state->distcode;
|
dcode = state->distcode;
|
||||||
lmask = (1U << state->lenbits) - 1;
|
lmask = (1U << state->lenbits) - 1;
|
||||||
dmask = (1U << state->distbits) - 1;
|
dmask = (1U << state->distbits) - 1;
|
||||||
|
|
||||||
/* decode literals and length/distances until end-of-block or not enough
|
/* decode literals and length/distances until end-of-block or not enough
|
||||||
input data or output space */
|
input data or output space */
|
||||||
do {
|
do {
|
||||||
if (bits < 15) {
|
if (bits < 15) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
this = lcode[hold & lmask];
|
this = lcode[hold & lmask];
|
||||||
dolen:
|
dolen:
|
||||||
op = (unsigned)(this.bits);
|
op = (unsigned)(this.bits);
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
op = (unsigned)(this.op);
|
op = (unsigned)(this.op);
|
||||||
if (op == 0) { /* literal */
|
if (op == 0) { /* literal */
|
||||||
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
|
||||||
"inflate: literal '%c'\n" :
|
"inflate: literal '%c'\n" :
|
||||||
"inflate: literal 0x%02x\n", this.val));
|
"inflate: literal 0x%02x\n", this.val));
|
||||||
PUP(out) = (unsigned char)(this.val);
|
PUP(out) = (unsigned char)(this.val);
|
||||||
}
|
}
|
||||||
else if (op & 16) { /* length base */
|
else if (op & 16) { /* length base */
|
||||||
len = (unsigned)(this.val);
|
len = (unsigned)(this.val);
|
||||||
op &= 15; /* number of extra bits */
|
op &= 15; /* number of extra bits */
|
||||||
if (op) {
|
if (op) {
|
||||||
if (bits < op) {
|
if (bits < op) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
len += (unsigned)hold & ((1U << op) - 1);
|
len += (unsigned)hold & ((1U << op) - 1);
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
}
|
}
|
||||||
Tracevv((stderr, "inflate: length %u\n", len));
|
Tracevv((stderr, "inflate: length %u\n", len));
|
||||||
if (bits < 15) {
|
if (bits < 15) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
this = dcode[hold & dmask];
|
this = dcode[hold & dmask];
|
||||||
dodist:
|
dodist:
|
||||||
op = (unsigned)(this.bits);
|
op = (unsigned)(this.bits);
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
op = (unsigned)(this.op);
|
op = (unsigned)(this.op);
|
||||||
if (op & 16) { /* distance base */
|
if (op & 16) { /* distance base */
|
||||||
dist = (unsigned)(this.val);
|
dist = (unsigned)(this.val);
|
||||||
op &= 15; /* number of extra bits */
|
op &= 15; /* number of extra bits */
|
||||||
if (bits < op) {
|
if (bits < op) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
if (bits < op) {
|
if (bits < op) {
|
||||||
hold += (unsigned long)(PUP(in)) << bits;
|
hold += (unsigned long)(PUP(in)) << bits;
|
||||||
bits += 8;
|
bits += 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dist += (unsigned)hold & ((1U << op) - 1);
|
dist += (unsigned)hold & ((1U << op) - 1);
|
||||||
hold >>= op;
|
hold >>= op;
|
||||||
bits -= op;
|
bits -= op;
|
||||||
Tracevv((stderr, "inflate: distance %u\n", dist));
|
Tracevv((stderr, "inflate: distance %u\n", dist));
|
||||||
op = (unsigned)(out - beg); /* max distance in output */
|
op = (unsigned)(out - beg); /* max distance in output */
|
||||||
if (dist > op) { /* see if copy from window */
|
if (dist > op) { /* see if copy from window */
|
||||||
op = dist - op; /* distance back in window */
|
op = dist - op; /* distance back in window */
|
||||||
if (op > whave) {
|
if (op > whave) {
|
||||||
strm->msg = (char *)"invalid distance too far back";
|
strm->msg = (char *)"invalid distance too far back";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
from = window - OFF;
|
from = window - OFF;
|
||||||
if (write == 0) { /* very common case */
|
if (write == 0) { /* very common case */
|
||||||
from += wsize - op;
|
from += wsize - op;
|
||||||
if (op < len) { /* some from window */
|
if (op < len) { /* some from window */
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = out - dist; /* rest from output */
|
from = out - dist; /* rest from output */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (write < op) { /* wrap around window */
|
else if (write < op) { /* wrap around window */
|
||||||
from += wsize + write - op;
|
from += wsize + write - op;
|
||||||
op -= write;
|
op -= write;
|
||||||
if (op < len) { /* some from end of window */
|
if (op < len) { /* some from end of window */
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = window - OFF;
|
from = window - OFF;
|
||||||
if (write < len) { /* some from start of window */
|
if (write < len) { /* some from start of window */
|
||||||
op = write;
|
op = write;
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = out - dist; /* rest from output */
|
from = out - dist; /* rest from output */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* contiguous in window */
|
else { /* contiguous in window */
|
||||||
from += write - op;
|
from += write - op;
|
||||||
if (op < len) { /* some from window */
|
if (op < len) { /* some from window */
|
||||||
len -= op;
|
len -= op;
|
||||||
do {
|
do {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
} while (--op);
|
} while (--op);
|
||||||
from = out - dist; /* rest from output */
|
from = out - dist; /* rest from output */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (len > 2) {
|
while (len > 2) {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
len -= 3;
|
len -= 3;
|
||||||
}
|
}
|
||||||
if (len) {
|
if (len) {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
from = out - dist; /* copy direct from output */
|
from = out - dist; /* copy direct from output */
|
||||||
do { /* minimum length is three */
|
do { /* minimum length is three */
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
len -= 3;
|
len -= 3;
|
||||||
} while (len > 2);
|
} while (len > 2);
|
||||||
if (len) {
|
if (len) {
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
PUP(out) = PUP(from);
|
PUP(out) = PUP(from);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((op & 64) == 0) { /* 2nd level distance code */
|
else if ((op & 64) == 0) { /* 2nd level distance code */
|
||||||
this = dcode[this.val + (hold & ((1U << op) - 1))];
|
this = dcode[this.val + (hold & ((1U << op) - 1))];
|
||||||
goto dodist;
|
goto dodist;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strm->msg = (char *)"invalid distance code";
|
strm->msg = (char *)"invalid distance code";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ((op & 64) == 0) { /* 2nd level length code */
|
else if ((op & 64) == 0) { /* 2nd level length code */
|
||||||
this = lcode[this.val + (hold & ((1U << op) - 1))];
|
this = lcode[this.val + (hold & ((1U << op) - 1))];
|
||||||
goto dolen;
|
goto dolen;
|
||||||
}
|
}
|
||||||
else if (op & 32) { /* end-of-block */
|
else if (op & 32) { /* end-of-block */
|
||||||
Tracevv((stderr, "inflate: end of block\n"));
|
Tracevv((stderr, "inflate: end of block\n"));
|
||||||
state->mode = TYPE;
|
state->mode = TYPE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strm->msg = (char *)"invalid literal/length code";
|
strm->msg = (char *)"invalid literal/length code";
|
||||||
state->mode = BAD;
|
state->mode = BAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (in < last && out < end);
|
} while (in < last && out < end);
|
||||||
|
|
||||||
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
/* return unused bytes (on entry, bits < 8, so in won't go too far back) */
|
||||||
len = bits >> 3;
|
len = bits >> 3;
|
||||||
in -= len;
|
in -= len;
|
||||||
bits -= len << 3;
|
bits -= len << 3;
|
||||||
hold &= (1U << bits) - 1;
|
hold &= (1U << bits) - 1;
|
||||||
|
|
||||||
/* update state and return */
|
/* update state and return */
|
||||||
strm->next_in = in + OFF;
|
strm->next_in = in + OFF;
|
||||||
strm->next_out = out + OFF;
|
strm->next_out = out + OFF;
|
||||||
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
|
||||||
strm->avail_out = (unsigned)(out < end ?
|
strm->avail_out = (unsigned)(out < end ?
|
||||||
257 + (end - out) : 257 - (out - end));
|
257 + (end - out) : 257 - (out - end));
|
||||||
state->hold = hold;
|
state->hold = hold;
|
||||||
state->bits = bits;
|
state->bits = bits;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
|
||||||
- Using bit fields for code structure
|
- Using bit fields for code structure
|
||||||
- Different op definition to avoid & for extra bits (do & for table bits)
|
- Different op definition to avoid & for extra bits (do & for table bits)
|
||||||
- Three separate decoding do-loops for direct, window, and write == 0
|
- Three separate decoding do-loops for direct, window, and write == 0
|
||||||
- Special case for distance > 1 copies to do overlapped load and store copy
|
- Special case for distance > 1 copies to do overlapped load and store copy
|
||||||
- Explicit branch predictions (based on measured branch probabilities)
|
- Explicit branch predictions (based on measured branch probabilities)
|
||||||
- Deferring match copy and interspersed it with decoding subsequent codes
|
- Deferring match copy and interspersed it with decoding subsequent codes
|
||||||
- Swapping literal/length else
|
- Swapping literal/length else
|
||||||
- Swapping window/direct else
|
- Swapping window/direct else
|
||||||
- Larger unrolled copy loops (three is about right)
|
- Larger unrolled copy loops (three is about right)
|
||||||
- Moving len -= 3 statement into middle of loop
|
- Moving len -= 3 statement into middle of loop
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#endif /* !ASMINF */
|
#endif /* !ASMINF */
|
||||||
|
|
2544
zlib/inflate.c
2544
zlib/inflate.c
File diff suppressed because it is too large
Load diff
649
zlib/inftrees.c
649
zlib/inftrees.c
|
@ -1,321 +1,328 @@
|
||||||
/* inftrees.c -- generate Huffman trees for efficient decoding
|
/* inftrees.c -- generate Huffman trees for efficient decoding
|
||||||
* Copyright (C) 1995-2003 Mark Adler
|
* Copyright (C) 1995-2004 Mark Adler
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "zutil.h"
|
#include "zutil.h"
|
||||||
#include "inftrees.h"
|
#include "inftrees.h"
|
||||||
|
|
||||||
#define MAXBITS 15
|
#define MAXBITS 15
|
||||||
|
|
||||||
const char inflate_copyright[] =
|
const char inflate_copyright[] =
|
||||||
" inflate 1.2.1 Copyright 1995-2003 Mark Adler ";
|
" inflate 1.2.2 Copyright 1995-2004 Mark Adler ";
|
||||||
/*
|
/*
|
||||||
If you use the zlib library in a product, an acknowledgment is welcome
|
If you use the zlib library in a product, an acknowledgment is welcome
|
||||||
in the documentation of your product. If for some reason you cannot
|
in the documentation of your product. If for some reason you cannot
|
||||||
include such an acknowledgment, I would appreciate that you keep this
|
include such an acknowledgment, I would appreciate that you keep this
|
||||||
copyright string in the executable of your product.
|
copyright string in the executable of your product.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Build a set of tables to decode the provided canonical Huffman code.
|
Build a set of tables to decode the provided canonical Huffman code.
|
||||||
The code lengths are lens[0..codes-1]. The result starts at *table,
|
The code lengths are lens[0..codes-1]. The result starts at *table,
|
||||||
whose indices are 0..2^bits-1. work is a writable array of at least
|
whose indices are 0..2^bits-1. work is a writable array of at least
|
||||||
lens shorts, which is used as a work area. type is the type of code
|
lens shorts, which is used as a work area. type is the type of code
|
||||||
to be generated, CODES, LENS, or DISTS. On return, zero is success,
|
to be generated, CODES, LENS, or DISTS. On return, zero is success,
|
||||||
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table
|
-1 is an invalid code, and +1 means that ENOUGH isn't enough. table
|
||||||
on return points to the next available entry's address. bits is the
|
on return points to the next available entry's address. bits is the
|
||||||
requested root table index bits, and on return it is the actual root
|
requested root table index bits, and on return it is the actual root
|
||||||
table index bits. It will differ if the request is greater than the
|
table index bits. It will differ if the request is greater than the
|
||||||
longest code or if it is less than the shortest code.
|
longest code or if it is less than the shortest code.
|
||||||
*/
|
*/
|
||||||
int inflate_table(type, lens, codes, table, bits, work)
|
int inflate_table(type, lens, codes, table, bits, work)
|
||||||
codetype type;
|
codetype type;
|
||||||
unsigned short FAR *lens;
|
unsigned short FAR *lens;
|
||||||
unsigned codes;
|
unsigned codes;
|
||||||
code FAR * FAR *table;
|
code FAR * FAR *table;
|
||||||
unsigned FAR *bits;
|
unsigned FAR *bits;
|
||||||
unsigned short FAR *work;
|
unsigned short FAR *work;
|
||||||
{
|
{
|
||||||
unsigned len; /* a code's length in bits */
|
unsigned len; /* a code's length in bits */
|
||||||
unsigned sym; /* index of code symbols */
|
unsigned sym; /* index of code symbols */
|
||||||
unsigned min, max; /* minimum and maximum code lengths */
|
unsigned min, max; /* minimum and maximum code lengths */
|
||||||
unsigned root; /* number of index bits for root table */
|
unsigned root; /* number of index bits for root table */
|
||||||
unsigned curr; /* number of index bits for current table */
|
unsigned curr; /* number of index bits for current table */
|
||||||
unsigned drop; /* code bits to drop for sub-table */
|
unsigned drop; /* code bits to drop for sub-table */
|
||||||
int left; /* number of prefix codes available */
|
int left; /* number of prefix codes available */
|
||||||
unsigned used; /* code entries in table used */
|
unsigned used; /* code entries in table used */
|
||||||
unsigned huff; /* Huffman code */
|
unsigned huff; /* Huffman code */
|
||||||
unsigned incr; /* for incrementing code, index */
|
unsigned incr; /* for incrementing code, index */
|
||||||
unsigned fill; /* index for replicating entries */
|
unsigned fill; /* index for replicating entries */
|
||||||
unsigned low; /* low bits for current root entry */
|
unsigned low; /* low bits for current root entry */
|
||||||
unsigned mask; /* mask for low root bits */
|
unsigned mask; /* mask for low root bits */
|
||||||
code this; /* table entry for duplication */
|
code this; /* table entry for duplication */
|
||||||
code FAR *next; /* next available space in table */
|
code FAR *next; /* next available space in table */
|
||||||
const unsigned short FAR *base; /* base value table to use */
|
const unsigned short FAR *base; /* base value table to use */
|
||||||
const unsigned short FAR *extra; /* extra bits table to use */
|
const unsigned short FAR *extra; /* extra bits table to use */
|
||||||
int end; /* use base and extra for symbol > end */
|
int end; /* use base and extra for symbol > end */
|
||||||
unsigned short count[MAXBITS+1]; /* number of codes of each length */
|
unsigned short count[MAXBITS+1]; /* number of codes of each length */
|
||||||
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
|
unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
|
||||||
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
|
static const unsigned short lbase[31] = { /* Length codes 257..285 base */
|
||||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
|
||||||
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
|
||||||
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
|
static const unsigned short lext[31] = { /* Length codes 257..285 extra */
|
||||||
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
|
16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
|
||||||
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 76, 66};
|
19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 199, 198};
|
||||||
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
|
static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
|
||||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
|
||||||
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
|
||||||
8193, 12289, 16385, 24577, 0, 0};
|
8193, 12289, 16385, 24577, 0, 0};
|
||||||
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
|
static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
|
||||||
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
|
16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
|
||||||
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
|
23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
|
||||||
28, 28, 29, 29, 64, 64};
|
28, 28, 29, 29, 64, 64};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Process a set of code lengths to create a canonical Huffman code. The
|
Process a set of code lengths to create a canonical Huffman code. The
|
||||||
code lengths are lens[0..codes-1]. Each length corresponds to the
|
code lengths are lens[0..codes-1]. Each length corresponds to the
|
||||||
symbols 0..codes-1. The Huffman code is generated by first sorting the
|
symbols 0..codes-1. The Huffman code is generated by first sorting the
|
||||||
symbols by length from short to long, and retaining the symbol order
|
symbols by length from short to long, and retaining the symbol order
|
||||||
for codes with equal lengths. Then the code starts with all zero bits
|
for codes with equal lengths. Then the code starts with all zero bits
|
||||||
for the first code of the shortest length, and the codes are integer
|
for the first code of the shortest length, and the codes are integer
|
||||||
increments for the same length, and zeros are appended as the length
|
increments for the same length, and zeros are appended as the length
|
||||||
increases. For the deflate format, these bits are stored backwards
|
increases. For the deflate format, these bits are stored backwards
|
||||||
from their more natural integer increment ordering, and so when the
|
from their more natural integer increment ordering, and so when the
|
||||||
decoding tables are built in the large loop below, the integer codes
|
decoding tables are built in the large loop below, the integer codes
|
||||||
are incremented backwards.
|
are incremented backwards.
|
||||||
|
|
||||||
This routine assumes, but does not check, that all of the entries in
|
This routine assumes, but does not check, that all of the entries in
|
||||||
lens[] are in the range 0..MAXBITS. The caller must assure this.
|
lens[] are in the range 0..MAXBITS. The caller must assure this.
|
||||||
1..MAXBITS is interpreted as that code length. zero means that that
|
1..MAXBITS is interpreted as that code length. zero means that that
|
||||||
symbol does not occur in this code.
|
symbol does not occur in this code.
|
||||||
|
|
||||||
The codes are sorted by computing a count of codes for each length,
|
The codes are sorted by computing a count of codes for each length,
|
||||||
creating from that a table of starting indices for each length in the
|
creating from that a table of starting indices for each length in the
|
||||||
sorted table, and then entering the symbols in order in the sorted
|
sorted table, and then entering the symbols in order in the sorted
|
||||||
table. The sorted table is work[], with that space being provided by
|
table. The sorted table is work[], with that space being provided by
|
||||||
the caller.
|
the caller.
|
||||||
|
|
||||||
The length counts are used for other purposes as well, i.e. finding
|
The length counts are used for other purposes as well, i.e. finding
|
||||||
the minimum and maximum length codes, determining if there are any
|
the minimum and maximum length codes, determining if there are any
|
||||||
codes at all, checking for a valid set of lengths, and looking ahead
|
codes at all, checking for a valid set of lengths, and looking ahead
|
||||||
at length counts to determine sub-table sizes when building the
|
at length counts to determine sub-table sizes when building the
|
||||||
decoding tables.
|
decoding tables.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
|
/* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
|
||||||
for (len = 0; len <= MAXBITS; len++)
|
for (len = 0; len <= MAXBITS; len++)
|
||||||
count[len] = 0;
|
count[len] = 0;
|
||||||
for (sym = 0; sym < codes; sym++)
|
for (sym = 0; sym < codes; sym++)
|
||||||
count[lens[sym]]++;
|
count[lens[sym]]++;
|
||||||
|
|
||||||
/* bound code lengths, force root to be within code lengths */
|
/* bound code lengths, force root to be within code lengths */
|
||||||
root = *bits;
|
root = *bits;
|
||||||
for (max = MAXBITS; max >= 1; max--)
|
for (max = MAXBITS; max >= 1; max--)
|
||||||
if (count[max] != 0) break;
|
if (count[max] != 0) break;
|
||||||
if (root > max) root = max;
|
if (root > max) root = max;
|
||||||
if (max == 0) return -1; /* no codes! */
|
if (max == 0) { /* no symbols to code at all */
|
||||||
for (min = 1; min <= MAXBITS; min++)
|
this.op = (unsigned char)64; /* invalid code marker */
|
||||||
if (count[min] != 0) break;
|
this.bits = (unsigned char)1;
|
||||||
if (root < min) root = min;
|
this.val = (unsigned short)0;
|
||||||
|
*(*table)++ = this; /* make a table to force an error */
|
||||||
/* check for an over-subscribed or incomplete set of lengths */
|
*(*table)++ = this;
|
||||||
left = 1;
|
*bits = 1;
|
||||||
for (len = 1; len <= MAXBITS; len++) {
|
return 0; /* no symbols, but wait for decoding to report error */
|
||||||
left <<= 1;
|
}
|
||||||
left -= count[len];
|
for (min = 1; min <= MAXBITS; min++)
|
||||||
if (left < 0) return -1; /* over-subscribed */
|
if (count[min] != 0) break;
|
||||||
}
|
if (root < min) root = min;
|
||||||
if (left > 0 && (type == CODES || (codes - count[0] != 1)))
|
|
||||||
return -1; /* incomplete set */
|
/* check for an over-subscribed or incomplete set of lengths */
|
||||||
|
left = 1;
|
||||||
/* generate offsets into symbol table for each length for sorting */
|
for (len = 1; len <= MAXBITS; len++) {
|
||||||
offs[1] = 0;
|
left <<= 1;
|
||||||
for (len = 1; len < MAXBITS; len++)
|
left -= count[len];
|
||||||
offs[len + 1] = offs[len] + count[len];
|
if (left < 0) return -1; /* over-subscribed */
|
||||||
|
}
|
||||||
/* sort symbols by length, by symbol order within each length */
|
if (left > 0 && (type == CODES || (codes - count[0] != 1)))
|
||||||
for (sym = 0; sym < codes; sym++)
|
return -1; /* incomplete set */
|
||||||
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
|
|
||||||
|
/* generate offsets into symbol table for each length for sorting */
|
||||||
/*
|
offs[1] = 0;
|
||||||
Create and fill in decoding tables. In this loop, the table being
|
for (len = 1; len < MAXBITS; len++)
|
||||||
filled is at next and has curr index bits. The code being used is huff
|
offs[len + 1] = offs[len] + count[len];
|
||||||
with length len. That code is converted to an index by dropping drop
|
|
||||||
bits off of the bottom. For codes where len is less than drop + curr,
|
/* sort symbols by length, by symbol order within each length */
|
||||||
those top drop + curr - len bits are incremented through all values to
|
for (sym = 0; sym < codes; sym++)
|
||||||
fill the table with replicated entries.
|
if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
|
||||||
|
|
||||||
root is the number of index bits for the root table. When len exceeds
|
/*
|
||||||
root, sub-tables are created pointed to by the root entry with an index
|
Create and fill in decoding tables. In this loop, the table being
|
||||||
of the low root bits of huff. This is saved in low to check for when a
|
filled is at next and has curr index bits. The code being used is huff
|
||||||
new sub-table should be started. drop is zero when the root table is
|
with length len. That code is converted to an index by dropping drop
|
||||||
being filled, and drop is root when sub-tables are being filled.
|
bits off of the bottom. For codes where len is less than drop + curr,
|
||||||
|
those top drop + curr - len bits are incremented through all values to
|
||||||
When a new sub-table is needed, it is necessary to look ahead in the
|
fill the table with replicated entries.
|
||||||
code lengths to determine what size sub-table is needed. The length
|
|
||||||
counts are used for this, and so count[] is decremented as codes are
|
root is the number of index bits for the root table. When len exceeds
|
||||||
entered in the tables.
|
root, sub-tables are created pointed to by the root entry with an index
|
||||||
|
of the low root bits of huff. This is saved in low to check for when a
|
||||||
used keeps track of how many table entries have been allocated from the
|
new sub-table should be started. drop is zero when the root table is
|
||||||
provided *table space. It is checked when a LENS table is being made
|
being filled, and drop is root when sub-tables are being filled.
|
||||||
against the space in *table, ENOUGH, minus the maximum space needed by
|
|
||||||
the worst case distance code, MAXD. This should never happen, but the
|
When a new sub-table is needed, it is necessary to look ahead in the
|
||||||
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
|
code lengths to determine what size sub-table is needed. The length
|
||||||
This assumes that when type == LENS, bits == 9.
|
counts are used for this, and so count[] is decremented as codes are
|
||||||
|
entered in the tables.
|
||||||
sym increments through all symbols, and the loop terminates when
|
|
||||||
all codes of length max, i.e. all codes, have been processed. This
|
used keeps track of how many table entries have been allocated from the
|
||||||
routine permits incomplete codes, so another loop after this one fills
|
provided *table space. It is checked when a LENS table is being made
|
||||||
in the rest of the decoding tables with invalid code markers.
|
against the space in *table, ENOUGH, minus the maximum space needed by
|
||||||
*/
|
the worst case distance code, MAXD. This should never happen, but the
|
||||||
|
sufficiency of ENOUGH has not been proven exhaustively, hence the check.
|
||||||
/* set up for code type */
|
This assumes that when type == LENS, bits == 9.
|
||||||
switch (type) {
|
|
||||||
case CODES:
|
sym increments through all symbols, and the loop terminates when
|
||||||
base = extra = work; /* dummy value--not used */
|
all codes of length max, i.e. all codes, have been processed. This
|
||||||
end = 19;
|
routine permits incomplete codes, so another loop after this one fills
|
||||||
break;
|
in the rest of the decoding tables with invalid code markers.
|
||||||
case LENS:
|
*/
|
||||||
base = lbase;
|
|
||||||
base -= 257;
|
/* set up for code type */
|
||||||
extra = lext;
|
switch (type) {
|
||||||
extra -= 257;
|
case CODES:
|
||||||
end = 256;
|
base = extra = work; /* dummy value--not used */
|
||||||
break;
|
end = 19;
|
||||||
default: /* DISTS */
|
break;
|
||||||
base = dbase;
|
case LENS:
|
||||||
extra = dext;
|
base = lbase;
|
||||||
end = -1;
|
base -= 257;
|
||||||
}
|
extra = lext;
|
||||||
|
extra -= 257;
|
||||||
/* initialize state for loop */
|
end = 256;
|
||||||
huff = 0; /* starting code */
|
break;
|
||||||
sym = 0; /* starting code symbol */
|
default: /* DISTS */
|
||||||
len = min; /* starting code length */
|
base = dbase;
|
||||||
next = *table; /* current table to fill in */
|
extra = dext;
|
||||||
curr = root; /* current table index bits */
|
end = -1;
|
||||||
drop = 0; /* current bits to drop from code for index */
|
}
|
||||||
low = (unsigned)(-1); /* trigger new sub-table when len > root */
|
|
||||||
used = 1U << root; /* use root table entries */
|
/* initialize state for loop */
|
||||||
mask = used - 1; /* mask for comparing low */
|
huff = 0; /* starting code */
|
||||||
|
sym = 0; /* starting code symbol */
|
||||||
/* check available table space */
|
len = min; /* starting code length */
|
||||||
if (type == LENS && used >= ENOUGH - MAXD)
|
next = *table; /* current table to fill in */
|
||||||
return 1;
|
curr = root; /* current table index bits */
|
||||||
|
drop = 0; /* current bits to drop from code for index */
|
||||||
/* process all codes and make table entries */
|
low = (unsigned)(-1); /* trigger new sub-table when len > root */
|
||||||
for (;;) {
|
used = 1U << root; /* use root table entries */
|
||||||
/* create table entry */
|
mask = used - 1; /* mask for comparing low */
|
||||||
this.bits = (unsigned char)(len - drop);
|
|
||||||
if ((int)(work[sym]) < end) {
|
/* check available table space */
|
||||||
this.op = (unsigned char)0;
|
if (type == LENS && used >= ENOUGH - MAXD)
|
||||||
this.val = work[sym];
|
return 1;
|
||||||
}
|
|
||||||
else if ((int)(work[sym]) > end) {
|
/* process all codes and make table entries */
|
||||||
this.op = (unsigned char)(extra[work[sym]]);
|
for (;;) {
|
||||||
this.val = base[work[sym]];
|
/* create table entry */
|
||||||
}
|
this.bits = (unsigned char)(len - drop);
|
||||||
else {
|
if ((int)(work[sym]) < end) {
|
||||||
this.op = (unsigned char)(32 + 64); /* end of block */
|
this.op = (unsigned char)0;
|
||||||
this.val = 0;
|
this.val = work[sym];
|
||||||
}
|
}
|
||||||
|
else if ((int)(work[sym]) > end) {
|
||||||
/* replicate for those indices with low len bits equal to huff */
|
this.op = (unsigned char)(extra[work[sym]]);
|
||||||
incr = 1U << (len - drop);
|
this.val = base[work[sym]];
|
||||||
fill = 1U << curr;
|
}
|
||||||
do {
|
else {
|
||||||
fill -= incr;
|
this.op = (unsigned char)(32 + 64); /* end of block */
|
||||||
next[(huff >> drop) + fill] = this;
|
this.val = 0;
|
||||||
} while (fill != 0);
|
}
|
||||||
|
|
||||||
/* backwards increment the len-bit code huff */
|
/* replicate for those indices with low len bits equal to huff */
|
||||||
incr = 1U << (len - 1);
|
incr = 1U << (len - drop);
|
||||||
while (huff & incr)
|
fill = 1U << curr;
|
||||||
incr >>= 1;
|
do {
|
||||||
if (incr != 0) {
|
fill -= incr;
|
||||||
huff &= incr - 1;
|
next[(huff >> drop) + fill] = this;
|
||||||
huff += incr;
|
} while (fill != 0);
|
||||||
}
|
|
||||||
else
|
/* backwards increment the len-bit code huff */
|
||||||
huff = 0;
|
incr = 1U << (len - 1);
|
||||||
|
while (huff & incr)
|
||||||
/* go to next symbol, update count, len */
|
incr >>= 1;
|
||||||
sym++;
|
if (incr != 0) {
|
||||||
if (--(count[len]) == 0) {
|
huff &= incr - 1;
|
||||||
if (len == max) break;
|
huff += incr;
|
||||||
len = lens[work[sym]];
|
}
|
||||||
}
|
else
|
||||||
|
huff = 0;
|
||||||
/* create new sub-table if needed */
|
|
||||||
if (len > root && (huff & mask) != low) {
|
/* go to next symbol, update count, len */
|
||||||
/* if first time, transition to sub-tables */
|
sym++;
|
||||||
if (drop == 0)
|
if (--(count[len]) == 0) {
|
||||||
drop = root;
|
if (len == max) break;
|
||||||
|
len = lens[work[sym]];
|
||||||
/* increment past last table */
|
}
|
||||||
next += 1U << curr;
|
|
||||||
|
/* create new sub-table if needed */
|
||||||
/* determine length of next table */
|
if (len > root && (huff & mask) != low) {
|
||||||
curr = len - drop;
|
/* if first time, transition to sub-tables */
|
||||||
left = (int)(1 << curr);
|
if (drop == 0)
|
||||||
while (curr + drop < max) {
|
drop = root;
|
||||||
left -= count[curr + drop];
|
|
||||||
if (left <= 0) break;
|
/* increment past last table */
|
||||||
curr++;
|
next += 1U << curr;
|
||||||
left <<= 1;
|
|
||||||
}
|
/* determine length of next table */
|
||||||
|
curr = len - drop;
|
||||||
/* check for enough space */
|
left = (int)(1 << curr);
|
||||||
used += 1U << curr;
|
while (curr + drop < max) {
|
||||||
if (type == LENS && used >= ENOUGH - MAXD)
|
left -= count[curr + drop];
|
||||||
return 1;
|
if (left <= 0) break;
|
||||||
|
curr++;
|
||||||
/* point entry in root table to sub-table */
|
left <<= 1;
|
||||||
low = huff & mask;
|
}
|
||||||
(*table)[low].op = (unsigned char)curr;
|
|
||||||
(*table)[low].bits = (unsigned char)root;
|
/* check for enough space */
|
||||||
(*table)[low].val = (unsigned short)(next - *table);
|
used += 1U << curr;
|
||||||
}
|
if (type == LENS && used >= ENOUGH - MAXD)
|
||||||
}
|
return 1;
|
||||||
|
|
||||||
/*
|
/* point entry in root table to sub-table */
|
||||||
Fill in rest of table for incomplete codes. This loop is similar to the
|
low = huff & mask;
|
||||||
loop above in incrementing huff for table indices. It is assumed that
|
(*table)[low].op = (unsigned char)curr;
|
||||||
len is equal to curr + drop, so there is no loop needed to increment
|
(*table)[low].bits = (unsigned char)root;
|
||||||
through high index bits. When the current sub-table is filled, the loop
|
(*table)[low].val = (unsigned short)(next - *table);
|
||||||
drops back to the root table to fill in any remaining entries there.
|
}
|
||||||
*/
|
}
|
||||||
this.op = (unsigned char)64; /* invalid code marker */
|
|
||||||
this.bits = (unsigned char)(len - drop);
|
/*
|
||||||
this.val = (unsigned short)0;
|
Fill in rest of table for incomplete codes. This loop is similar to the
|
||||||
while (huff != 0) {
|
loop above in incrementing huff for table indices. It is assumed that
|
||||||
/* when done with sub-table, drop back to root table */
|
len is equal to curr + drop, so there is no loop needed to increment
|
||||||
if (drop != 0 && (huff & mask) != low) {
|
through high index bits. When the current sub-table is filled, the loop
|
||||||
drop = 0;
|
drops back to the root table to fill in any remaining entries there.
|
||||||
len = root;
|
*/
|
||||||
next = *table;
|
this.op = (unsigned char)64; /* invalid code marker */
|
||||||
curr = root;
|
this.bits = (unsigned char)(len - drop);
|
||||||
this.bits = (unsigned char)len;
|
this.val = (unsigned short)0;
|
||||||
}
|
while (huff != 0) {
|
||||||
|
/* when done with sub-table, drop back to root table */
|
||||||
/* put invalid code marker in table */
|
if (drop != 0 && (huff & mask) != low) {
|
||||||
next[huff >> drop] = this;
|
drop = 0;
|
||||||
|
len = root;
|
||||||
/* backwards increment the len-bit code huff */
|
next = *table;
|
||||||
incr = 1U << (len - 1);
|
this.bits = (unsigned char)len;
|
||||||
while (huff & incr)
|
}
|
||||||
incr >>= 1;
|
|
||||||
if (incr != 0) {
|
/* put invalid code marker in table */
|
||||||
huff &= incr - 1;
|
next[huff >> drop] = this;
|
||||||
huff += incr;
|
|
||||||
}
|
/* backwards increment the len-bit code huff */
|
||||||
else
|
incr = 1U << (len - 1);
|
||||||
huff = 0;
|
while (huff & incr)
|
||||||
}
|
incr >>= 1;
|
||||||
|
if (incr != 0) {
|
||||||
/* set return parameters */
|
huff &= incr - 1;
|
||||||
*table += used;
|
huff += incr;
|
||||||
*bits = root;
|
}
|
||||||
return 0;
|
else
|
||||||
}
|
huff = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* set return parameters */
|
||||||
|
*table += used;
|
||||||
|
*bits = root;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
649
zlib/zconf.h
649
zlib/zconf.h
|
@ -1,323 +1,326 @@
|
||||||
/* zconf.h -- configuration of the zlib compression library
|
/* zconf.h -- configuration of the zlib compression library
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2004 Jean-loup Gailly.
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
#ifndef ZCONF_H
|
#ifndef ZCONF_H
|
||||||
#define ZCONF_H
|
#define ZCONF_H
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If you *really* need a unique prefix for all types and library functions,
|
* If you *really* need a unique prefix for all types and library functions,
|
||||||
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
|
||||||
*/
|
*/
|
||||||
#ifdef Z_PREFIX
|
#ifdef Z_PREFIX
|
||||||
# define deflateInit_ z_deflateInit_
|
# define deflateInit_ z_deflateInit_
|
||||||
# define deflate z_deflate
|
# define deflate z_deflate
|
||||||
# define deflateEnd z_deflateEnd
|
# define deflateEnd z_deflateEnd
|
||||||
# define inflateInit_ z_inflateInit_
|
# define inflateInit_ z_inflateInit_
|
||||||
# define inflate z_inflate
|
# define inflate z_inflate
|
||||||
# define inflateEnd z_inflateEnd
|
# define inflateEnd z_inflateEnd
|
||||||
# define deflateInit2_ z_deflateInit2_
|
# define deflateInit2_ z_deflateInit2_
|
||||||
# define deflateSetDictionary z_deflateSetDictionary
|
# define deflateSetDictionary z_deflateSetDictionary
|
||||||
# define deflateCopy z_deflateCopy
|
# define deflateCopy z_deflateCopy
|
||||||
# define deflateReset z_deflateReset
|
# define deflateReset z_deflateReset
|
||||||
# define deflatePrime z_deflatePrime
|
# define deflateParams z_deflateParams
|
||||||
# define deflateParams z_deflateParams
|
# define deflateBound z_deflateBound
|
||||||
# define deflateBound z_deflateBound
|
# define deflatePrime z_deflatePrime
|
||||||
# define inflateInit2_ z_inflateInit2_
|
# define inflateInit2_ z_inflateInit2_
|
||||||
# define inflateSetDictionary z_inflateSetDictionary
|
# define inflateSetDictionary z_inflateSetDictionary
|
||||||
# define inflateSync z_inflateSync
|
# define inflateSync z_inflateSync
|
||||||
# define inflateSyncPoint z_inflateSyncPoint
|
# define inflateSyncPoint z_inflateSyncPoint
|
||||||
# define inflateCopy z_inflateCopy
|
# define inflateCopy z_inflateCopy
|
||||||
# define inflateReset z_inflateReset
|
# define inflateReset z_inflateReset
|
||||||
# define compress z_compress
|
# define inflateBack z_inflateBack
|
||||||
# define compress2 z_compress2
|
# define inflateBackEnd z_inflateBackEnd
|
||||||
# define compressBound z_compressBound
|
# define compress z_compress
|
||||||
# define uncompress z_uncompress
|
# define compress2 z_compress2
|
||||||
# define adler32 z_adler32
|
# define compressBound z_compressBound
|
||||||
# define crc32 z_crc32
|
# define uncompress z_uncompress
|
||||||
# define get_crc_table z_get_crc_table
|
# define adler32 z_adler32
|
||||||
|
# define crc32 z_crc32
|
||||||
# define Byte z_Byte
|
# define get_crc_table z_get_crc_table
|
||||||
# define uInt z_uInt
|
# define zError z_zError
|
||||||
# define uLong z_uLong
|
|
||||||
# define Bytef z_Bytef
|
# define Byte z_Byte
|
||||||
# define charf z_charf
|
# define uInt z_uInt
|
||||||
# define intf z_intf
|
# define uLong z_uLong
|
||||||
# define uIntf z_uIntf
|
# define Bytef z_Bytef
|
||||||
# define uLongf z_uLongf
|
# define charf z_charf
|
||||||
# define voidpf z_voidpf
|
# define intf z_intf
|
||||||
# define voidp z_voidp
|
# define uIntf z_uIntf
|
||||||
#endif
|
# define uLongf z_uLongf
|
||||||
|
# define voidpf z_voidpf
|
||||||
#if defined(__MSDOS__) && !defined(MSDOS)
|
# define voidp z_voidp
|
||||||
# define MSDOS
|
#endif
|
||||||
#endif
|
|
||||||
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
#if defined(__MSDOS__) && !defined(MSDOS)
|
||||||
# define OS2
|
# define MSDOS
|
||||||
#endif
|
#endif
|
||||||
#if defined(_WINDOWS) && !defined(WINDOWS)
|
#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
|
||||||
# define WINDOWS
|
# define OS2
|
||||||
#endif
|
#endif
|
||||||
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
#if defined(_WINDOWS) && !defined(WINDOWS)
|
||||||
# define WIN32
|
# define WINDOWS
|
||||||
#endif
|
#endif
|
||||||
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
|
||||||
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
# define WIN32
|
||||||
# ifndef SYS16BIT
|
#endif
|
||||||
# define SYS16BIT
|
#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
|
||||||
# endif
|
# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
|
||||||
# endif
|
# ifndef SYS16BIT
|
||||||
#endif
|
# define SYS16BIT
|
||||||
|
# endif
|
||||||
/*
|
# endif
|
||||||
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
#endif
|
||||||
* than 64k bytes at a time (needed on systems with 16-bit int).
|
|
||||||
*/
|
/*
|
||||||
#ifdef SYS16BIT
|
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
|
||||||
# define MAXSEG_64K
|
* than 64k bytes at a time (needed on systems with 16-bit int).
|
||||||
#endif
|
*/
|
||||||
#ifdef MSDOS
|
#ifdef SYS16BIT
|
||||||
# define UNALIGNED_OK
|
# define MAXSEG_64K
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MSDOS
|
||||||
#ifdef __STDC_VERSION__
|
# define UNALIGNED_OK
|
||||||
# ifndef STDC
|
#endif
|
||||||
# define STDC
|
|
||||||
# endif
|
#ifdef __STDC_VERSION__
|
||||||
# if __STDC_VERSION__ >= 199901L
|
# ifndef STDC
|
||||||
# ifndef STDC99
|
# define STDC
|
||||||
# define STDC99
|
# endif
|
||||||
# endif
|
# if __STDC_VERSION__ >= 199901L
|
||||||
# endif
|
# ifndef STDC99
|
||||||
#endif
|
# define STDC99
|
||||||
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
# endif
|
||||||
# define STDC
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
|
||||||
# define STDC
|
# define STDC
|
||||||
#endif
|
#endif
|
||||||
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
|
||||||
# define STDC
|
# define STDC
|
||||||
#endif
|
#endif
|
||||||
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
|
||||||
# define STDC
|
# define STDC
|
||||||
#endif
|
#endif
|
||||||
|
#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
|
||||||
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
# define STDC
|
||||||
# define STDC
|
#endif
|
||||||
#endif
|
|
||||||
|
#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
|
||||||
#ifndef STDC
|
# define STDC
|
||||||
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
#endif
|
||||||
# define const /* note: need a more gentle solution here */
|
|
||||||
# endif
|
#ifndef STDC
|
||||||
#endif
|
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
|
||||||
|
# define const /* note: need a more gentle solution here */
|
||||||
/* Some Mac compilers merge all .h files incorrectly: */
|
# endif
|
||||||
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
#endif
|
||||||
# define NO_DUMMY_DECL
|
|
||||||
#endif
|
/* Some Mac compilers merge all .h files incorrectly: */
|
||||||
|
#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
|
||||||
/* Maximum value for memLevel in deflateInit2 */
|
# define NO_DUMMY_DECL
|
||||||
#ifndef MAX_MEM_LEVEL
|
#endif
|
||||||
# ifdef MAXSEG_64K
|
|
||||||
# define MAX_MEM_LEVEL 8
|
/* Maximum value for memLevel in deflateInit2 */
|
||||||
# else
|
#ifndef MAX_MEM_LEVEL
|
||||||
# define MAX_MEM_LEVEL 9
|
# ifdef MAXSEG_64K
|
||||||
# endif
|
# define MAX_MEM_LEVEL 8
|
||||||
#endif
|
# else
|
||||||
|
# define MAX_MEM_LEVEL 9
|
||||||
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
# endif
|
||||||
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
#endif
|
||||||
* created by gzip. (Files created by minigzip can still be extracted by
|
|
||||||
* gzip.)
|
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
|
||||||
*/
|
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
|
||||||
#ifndef MAX_WBITS
|
* created by gzip. (Files created by minigzip can still be extracted by
|
||||||
# define MAX_WBITS 15 /* 32K LZ77 window */
|
* gzip.)
|
||||||
#endif
|
*/
|
||||||
|
#ifndef MAX_WBITS
|
||||||
/* The memory requirements for deflate are (in bytes):
|
# define MAX_WBITS 15 /* 32K LZ77 window */
|
||||||
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
#endif
|
||||||
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
|
||||||
plus a few kilobytes for small objects. For example, if you want to reduce
|
/* The memory requirements for deflate are (in bytes):
|
||||||
the default memory requirements from 256K to 128K, compile with
|
(1 << (windowBits+2)) + (1 << (memLevel+9))
|
||||||
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
|
||||||
Of course this will generally degrade compression (there's no free lunch).
|
plus a few kilobytes for small objects. For example, if you want to reduce
|
||||||
|
the default memory requirements from 256K to 128K, compile with
|
||||||
The memory requirements for inflate are (in bytes) 1 << windowBits
|
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
|
||||||
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
Of course this will generally degrade compression (there's no free lunch).
|
||||||
for small objects.
|
|
||||||
*/
|
The memory requirements for inflate are (in bytes) 1 << windowBits
|
||||||
|
that is, 32K for windowBits=15 (default value) plus a few kilobytes
|
||||||
/* Type declarations */
|
for small objects.
|
||||||
|
*/
|
||||||
#ifndef OF /* function prototypes */
|
|
||||||
# ifdef STDC
|
/* Type declarations */
|
||||||
# define OF(args) args
|
|
||||||
# else
|
#ifndef OF /* function prototypes */
|
||||||
# define OF(args) ()
|
# ifdef STDC
|
||||||
# endif
|
# define OF(args) args
|
||||||
#endif
|
# else
|
||||||
|
# define OF(args) ()
|
||||||
/* The following definitions for FAR are needed only for MSDOS mixed
|
# endif
|
||||||
* model programming (small or medium model with some far allocations).
|
#endif
|
||||||
* This was tested only with MSC; for other MSDOS compilers you may have
|
|
||||||
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
/* The following definitions for FAR are needed only for MSDOS mixed
|
||||||
* just define FAR to be empty.
|
* model programming (small or medium model with some far allocations).
|
||||||
*/
|
* This was tested only with MSC; for other MSDOS compilers you may have
|
||||||
#ifdef SYS16BIT
|
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
|
||||||
# if defined(M_I86SM) || defined(M_I86MM)
|
* just define FAR to be empty.
|
||||||
/* MSC small or medium model */
|
*/
|
||||||
# define SMALL_MEDIUM
|
#ifdef SYS16BIT
|
||||||
# ifdef _MSC_VER
|
# if defined(M_I86SM) || defined(M_I86MM)
|
||||||
# define FAR _far
|
/* MSC small or medium model */
|
||||||
# else
|
# define SMALL_MEDIUM
|
||||||
# define FAR far
|
# ifdef _MSC_VER
|
||||||
# endif
|
# define FAR _far
|
||||||
# endif
|
# else
|
||||||
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
# define FAR far
|
||||||
/* Turbo C small or medium model */
|
# endif
|
||||||
# define SMALL_MEDIUM
|
# endif
|
||||||
# ifdef __BORLANDC__
|
# if (defined(__SMALL__) || defined(__MEDIUM__))
|
||||||
# define FAR _far
|
/* Turbo C small or medium model */
|
||||||
# else
|
# define SMALL_MEDIUM
|
||||||
# define FAR far
|
# ifdef __BORLANDC__
|
||||||
# endif
|
# define FAR _far
|
||||||
# endif
|
# else
|
||||||
#endif
|
# define FAR far
|
||||||
|
# endif
|
||||||
#if defined(WINDOWS) || defined(WIN32)
|
# endif
|
||||||
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
#endif
|
||||||
* This is not mandatory, but it offers a little performance increase.
|
|
||||||
*/
|
#if defined(WINDOWS) || defined(WIN32)
|
||||||
# ifdef ZLIB_DLL
|
/* If building or using zlib as a DLL, define ZLIB_DLL.
|
||||||
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
* This is not mandatory, but it offers a little performance increase.
|
||||||
# ifdef ZLIB_INTERNAL
|
*/
|
||||||
# define ZEXTERN extern __declspec(dllexport)
|
# ifdef ZLIB_DLL
|
||||||
# else
|
# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
|
||||||
# define ZEXTERN extern __declspec(dllimport)
|
# ifdef ZLIB_INTERNAL
|
||||||
# endif
|
# define ZEXTERN extern __declspec(dllexport)
|
||||||
# endif
|
# else
|
||||||
# endif /* ZLIB_DLL */
|
# define ZEXTERN extern __declspec(dllimport)
|
||||||
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
# endif
|
||||||
* define ZLIB_WINAPI.
|
# endif
|
||||||
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
# endif /* ZLIB_DLL */
|
||||||
*/
|
/* If building or using zlib with the WINAPI/WINAPIV calling convention,
|
||||||
# ifdef ZLIB_WINAPI
|
* define ZLIB_WINAPI.
|
||||||
# ifdef FAR
|
* Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
|
||||||
# undef FAR
|
*/
|
||||||
# endif
|
# ifdef ZLIB_WINAPI
|
||||||
# include <windows.h>
|
# ifdef FAR
|
||||||
/* No need for _export, use ZLIB.DEF instead. */
|
# undef FAR
|
||||||
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
# endif
|
||||||
# define ZEXPORT WINAPI
|
# include <windows.h>
|
||||||
# ifdef WIN32
|
/* No need for _export, use ZLIB.DEF instead. */
|
||||||
# define ZEXPORTVA WINAPIV
|
/* For complete Windows compatibility, use WINAPI, not __stdcall. */
|
||||||
# else
|
# define ZEXPORT WINAPI
|
||||||
# define ZEXPORTVA FAR CDECL
|
# ifdef WIN32
|
||||||
# endif
|
# define ZEXPORTVA WINAPIV
|
||||||
# endif
|
# else
|
||||||
#endif
|
# define ZEXPORTVA FAR CDECL
|
||||||
|
# endif
|
||||||
#if defined (__BEOS__)
|
# endif
|
||||||
# ifdef ZLIB_DLL
|
#endif
|
||||||
# ifdef ZLIB_INTERNAL
|
|
||||||
# define ZEXPORT __declspec(dllexport)
|
#if defined (__BEOS__)
|
||||||
# define ZEXPORTVA __declspec(dllexport)
|
# ifdef ZLIB_DLL
|
||||||
# else
|
# ifdef ZLIB_INTERNAL
|
||||||
# define ZEXPORT __declspec(dllimport)
|
# define ZEXPORT __declspec(dllexport)
|
||||||
# define ZEXPORTVA __declspec(dllimport)
|
# define ZEXPORTVA __declspec(dllexport)
|
||||||
# endif
|
# else
|
||||||
# endif
|
# define ZEXPORT __declspec(dllimport)
|
||||||
#endif
|
# define ZEXPORTVA __declspec(dllimport)
|
||||||
|
# endif
|
||||||
#ifndef ZEXTERN
|
# endif
|
||||||
# define ZEXTERN extern
|
#endif
|
||||||
#endif
|
|
||||||
#ifndef ZEXPORT
|
#ifndef ZEXTERN
|
||||||
# define ZEXPORT
|
# define ZEXTERN extern
|
||||||
#endif
|
#endif
|
||||||
#ifndef ZEXPORTVA
|
#ifndef ZEXPORT
|
||||||
# define ZEXPORTVA
|
# define ZEXPORT
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ZEXPORTVA
|
||||||
#ifndef FAR
|
# define ZEXPORTVA
|
||||||
# define FAR
|
#endif
|
||||||
#endif
|
|
||||||
|
#ifndef FAR
|
||||||
#if !defined(__MACTYPES__)
|
# define FAR
|
||||||
typedef unsigned char Byte; /* 8 bits */
|
#endif
|
||||||
#endif
|
|
||||||
typedef unsigned int uInt; /* 16 bits or more */
|
#if !defined(__MACTYPES__)
|
||||||
typedef unsigned long uLong; /* 32 bits or more */
|
typedef unsigned char Byte; /* 8 bits */
|
||||||
|
#endif
|
||||||
#ifdef SMALL_MEDIUM
|
typedef unsigned int uInt; /* 16 bits or more */
|
||||||
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
typedef unsigned long uLong; /* 32 bits or more */
|
||||||
# define Bytef Byte FAR
|
|
||||||
#else
|
#ifdef SMALL_MEDIUM
|
||||||
typedef Byte FAR Bytef;
|
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
|
||||||
#endif
|
# define Bytef Byte FAR
|
||||||
typedef char FAR charf;
|
#else
|
||||||
typedef int FAR intf;
|
typedef Byte FAR Bytef;
|
||||||
typedef uInt FAR uIntf;
|
#endif
|
||||||
typedef uLong FAR uLongf;
|
typedef char FAR charf;
|
||||||
|
typedef int FAR intf;
|
||||||
#ifdef STDC
|
typedef uInt FAR uIntf;
|
||||||
typedef void const *voidpc;
|
typedef uLong FAR uLongf;
|
||||||
typedef void FAR *voidpf;
|
|
||||||
typedef void *voidp;
|
#ifdef STDC
|
||||||
#else
|
typedef void const *voidpc;
|
||||||
typedef Byte const *voidpc;
|
typedef void FAR *voidpf;
|
||||||
typedef Byte FAR *voidpf;
|
typedef void *voidp;
|
||||||
typedef Byte *voidp;
|
#else
|
||||||
#endif
|
typedef Byte const *voidpc;
|
||||||
|
typedef Byte FAR *voidpf;
|
||||||
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
typedef Byte *voidp;
|
||||||
# include <sys/types.h> /* for off_t */
|
#endif
|
||||||
# include <unistd.h> /* for SEEK_* and off_t */
|
|
||||||
# ifdef VMS
|
#if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
|
||||||
# include <unixio.h> /* for off_t */
|
# include <sys/types.h> /* for off_t */
|
||||||
# endif
|
# include <unistd.h> /* for SEEK_* and off_t */
|
||||||
# define z_off_t off_t
|
# ifdef VMS
|
||||||
#endif
|
# include <unixio.h> /* for off_t */
|
||||||
#ifndef SEEK_SET
|
# endif
|
||||||
# define SEEK_SET 0 /* Seek from beginning of file. */
|
# define z_off_t off_t
|
||||||
# define SEEK_CUR 1 /* Seek from current position. */
|
#endif
|
||||||
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
#ifndef SEEK_SET
|
||||||
#endif
|
# define SEEK_SET 0 /* Seek from beginning of file. */
|
||||||
#ifndef z_off_t
|
# define SEEK_CUR 1 /* Seek from current position. */
|
||||||
# define z_off_t long
|
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef z_off_t
|
||||||
#if defined(__OS400__)
|
# define z_off_t long
|
||||||
#define NO_vsnprintf
|
#endif
|
||||||
#endif
|
|
||||||
|
#if defined(__OS400__)
|
||||||
#if defined(__MVS__)
|
# define NO_vsnprintf
|
||||||
# define NO_vsnprintf
|
#endif
|
||||||
# ifdef FAR
|
|
||||||
# undef FAR
|
#if defined(__MVS__)
|
||||||
# endif
|
# define NO_vsnprintf
|
||||||
#endif
|
# ifdef FAR
|
||||||
|
# undef FAR
|
||||||
/* MVS linker does not support external names larger than 8 bytes */
|
# endif
|
||||||
#if defined(__MVS__)
|
#endif
|
||||||
# pragma map(deflateInit_,"DEIN")
|
|
||||||
# pragma map(deflateInit2_,"DEIN2")
|
/* MVS linker does not support external names larger than 8 bytes */
|
||||||
# pragma map(deflateEnd,"DEEND")
|
#if defined(__MVS__)
|
||||||
# pragma map(deflateBound,"DEBND")
|
# pragma map(deflateInit_,"DEIN")
|
||||||
# pragma map(inflateInit_,"ININ")
|
# pragma map(deflateInit2_,"DEIN2")
|
||||||
# pragma map(inflateInit2_,"ININ2")
|
# pragma map(deflateEnd,"DEEND")
|
||||||
# pragma map(inflateEnd,"INEND")
|
# pragma map(deflateBound,"DEBND")
|
||||||
# pragma map(inflateSync,"INSY")
|
# pragma map(inflateInit_,"ININ")
|
||||||
# pragma map(inflateSetDictionary,"INSEDI")
|
# pragma map(inflateInit2_,"ININ2")
|
||||||
# pragma map(compressBound,"CMBND")
|
# pragma map(inflateEnd,"INEND")
|
||||||
# pragma map(inflate_table,"INTABL")
|
# pragma map(inflateSync,"INSY")
|
||||||
# pragma map(inflate_fast,"INFA")
|
# pragma map(inflateSetDictionary,"INSEDI")
|
||||||
# pragma map(inflate_copyright,"INCOPY")
|
# pragma map(compressBound,"CMBND")
|
||||||
#endif
|
# pragma map(inflate_table,"INTABL")
|
||||||
|
# pragma map(inflate_fast,"INFA")
|
||||||
#endif /* ZCONF_H */
|
# pragma map(inflate_copyright,"INCOPY")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZCONF_H */
|
||||||
|
|
2400
zlib/zlib.h
2400
zlib/zlib.h
File diff suppressed because it is too large
Load diff
521
zlib/zutil.h
521
zlib/zutil.h
|
@ -1,258 +1,263 @@
|
||||||
/* zutil.h -- internal interface and configuration of the compression library
|
/* zutil.h -- internal interface and configuration of the compression library
|
||||||
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
* Copyright (C) 1995-2003 Jean-loup Gailly.
|
||||||
* For conditions of distribution and use, see copyright notice in zlib.h
|
* For conditions of distribution and use, see copyright notice in zlib.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* WARNING: this file should *not* be used by applications. It is
|
/* WARNING: this file should *not* be used by applications. It is
|
||||||
part of the implementation of the compression library and is
|
part of the implementation of the compression library and is
|
||||||
subject to change. Applications should only use zlib.h.
|
subject to change. Applications should only use zlib.h.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* @(#) $Id$ */
|
/* @(#) $Id$ */
|
||||||
|
|
||||||
#ifndef ZUTIL_H
|
#ifndef ZUTIL_H
|
||||||
#define ZUTIL_H
|
#define ZUTIL_H
|
||||||
|
|
||||||
#define ZLIB_INTERNAL
|
#define ZLIB_INTERNAL
|
||||||
#include "zlib.h"
|
#include "zlib.h"
|
||||||
|
|
||||||
#ifdef STDC
|
#ifdef STDC
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
# include <string.h>
|
# include <string.h>
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef NO_ERRNO_H
|
#ifdef NO_ERRNO_H
|
||||||
extern int errno;
|
extern int errno;
|
||||||
#else
|
#else
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef local
|
#ifndef local
|
||||||
# define local static
|
# define local static
|
||||||
#endif
|
#endif
|
||||||
/* compile with -Dlocal if your debugger can't find static symbols */
|
/* compile with -Dlocal if your debugger can't find static symbols */
|
||||||
|
|
||||||
typedef unsigned char uch;
|
typedef unsigned char uch;
|
||||||
typedef uch FAR uchf;
|
typedef uch FAR uchf;
|
||||||
typedef unsigned short ush;
|
typedef unsigned short ush;
|
||||||
typedef ush FAR ushf;
|
typedef ush FAR ushf;
|
||||||
typedef unsigned long ulg;
|
typedef unsigned long ulg;
|
||||||
|
|
||||||
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
|
||||||
/* (size given to avoid silly warnings with Visual C++) */
|
/* (size given to avoid silly warnings with Visual C++) */
|
||||||
|
|
||||||
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
|
||||||
|
|
||||||
#define ERR_RETURN(strm,err) \
|
#define ERR_RETURN(strm,err) \
|
||||||
return (strm->msg = (char*)ERR_MSG(err), (err))
|
return (strm->msg = (char*)ERR_MSG(err), (err))
|
||||||
/* To be used only when the state is known to be valid */
|
/* To be used only when the state is known to be valid */
|
||||||
|
|
||||||
/* common constants */
|
/* common constants */
|
||||||
|
|
||||||
#ifndef DEF_WBITS
|
#ifndef DEF_WBITS
|
||||||
# define DEF_WBITS MAX_WBITS
|
# define DEF_WBITS MAX_WBITS
|
||||||
#endif
|
#endif
|
||||||
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
/* default windowBits for decompression. MAX_WBITS is for compression only */
|
||||||
|
|
||||||
#if MAX_MEM_LEVEL >= 8
|
#if MAX_MEM_LEVEL >= 8
|
||||||
# define DEF_MEM_LEVEL 8
|
# define DEF_MEM_LEVEL 8
|
||||||
#else
|
#else
|
||||||
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
|
||||||
#endif
|
#endif
|
||||||
/* default memLevel */
|
/* default memLevel */
|
||||||
|
|
||||||
#define STORED_BLOCK 0
|
#define STORED_BLOCK 0
|
||||||
#define STATIC_TREES 1
|
#define STATIC_TREES 1
|
||||||
#define DYN_TREES 2
|
#define DYN_TREES 2
|
||||||
/* The three kinds of block type */
|
/* The three kinds of block type */
|
||||||
|
|
||||||
#define MIN_MATCH 3
|
#define MIN_MATCH 3
|
||||||
#define MAX_MATCH 258
|
#define MAX_MATCH 258
|
||||||
/* The minimum and maximum match lengths */
|
/* The minimum and maximum match lengths */
|
||||||
|
|
||||||
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
|
||||||
|
|
||||||
/* target dependencies */
|
/* target dependencies */
|
||||||
|
|
||||||
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
|
||||||
# define OS_CODE 0x00
|
# define OS_CODE 0x00
|
||||||
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
# if defined(__TURBOC__) || defined(__BORLANDC__)
|
||||||
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
|
||||||
/* Allow compilation with ANSI keywords only enabled */
|
/* Allow compilation with ANSI keywords only enabled */
|
||||||
void _Cdecl farfree( void *block );
|
void _Cdecl farfree( void *block );
|
||||||
void *_Cdecl farmalloc( unsigned long nbytes );
|
void *_Cdecl farmalloc( unsigned long nbytes );
|
||||||
# else
|
# else
|
||||||
# include <alloc.h>
|
# include <alloc.h>
|
||||||
# endif
|
# endif
|
||||||
# else /* MSC or DJGPP */
|
# else /* MSC or DJGPP */
|
||||||
# include <malloc.h>
|
# include <malloc.h>
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AMIGA
|
#ifdef AMIGA
|
||||||
# define OS_CODE 0x01
|
# define OS_CODE 0x01
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(VAXC) || defined(VMS)
|
#if defined(VAXC) || defined(VMS)
|
||||||
# define OS_CODE 0x02
|
# define OS_CODE 0x02
|
||||||
# define F_OPEN(name, mode) \
|
# define F_OPEN(name, mode) \
|
||||||
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ATARI) || defined(atarist)
|
#if defined(ATARI) || defined(atarist)
|
||||||
# define OS_CODE 0x05
|
# define OS_CODE 0x05
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OS2
|
#ifdef OS2
|
||||||
# define OS_CODE 0x06
|
# define OS_CODE 0x06
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
#if defined(MACOS) || defined(TARGET_OS_MAC)
|
||||||
# define OS_CODE 0x07
|
# define OS_CODE 0x07
|
||||||
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
||||||
# include <unix.h> /* for fdopen */
|
# include <unix.h> /* for fdopen */
|
||||||
# else
|
# else
|
||||||
# ifndef fdopen
|
# ifndef fdopen
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TOPS20
|
#ifdef TOPS20
|
||||||
# define OS_CODE 0x0a
|
# define OS_CODE 0x0a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
|
# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
|
||||||
# define OS_CODE 0x0b
|
# define OS_CODE 0x0b
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __50SERIES /* Prime/PRIMOS */
|
#ifdef __50SERIES /* Prime/PRIMOS */
|
||||||
# define OS_CODE 0x0f
|
# define OS_CODE 0x0f
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_BEOS_) || defined(RISCOS)
|
#if defined(_BEOS_) || defined(RISCOS)
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
#if (defined(_MSC_VER) && (_MSC_VER > 600))
|
||||||
# if defined(_WIN32_WCE)
|
# if defined(_WIN32_WCE)
|
||||||
# define fdopen(fd,mode) NULL /* No fdopen() */
|
# define fdopen(fd,mode) NULL /* No fdopen() */
|
||||||
# ifndef _PTRDIFF_T_DEFINED
|
# ifndef _PTRDIFF_T_DEFINED
|
||||||
typedef int ptrdiff_t;
|
typedef int ptrdiff_t;
|
||||||
# define _PTRDIFF_T_DEFINED
|
# define _PTRDIFF_T_DEFINED
|
||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
# define fdopen(fd,type) _fdopen(fd,type)
|
# define fdopen(fd,type) _fdopen(fd,type)
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* common defaults */
|
/* common defaults */
|
||||||
|
|
||||||
#ifndef OS_CODE
|
#ifndef OS_CODE
|
||||||
# define OS_CODE 0x03 /* assume Unix */
|
# define OS_CODE 0x03 /* assume Unix */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef F_OPEN
|
#ifndef F_OPEN
|
||||||
# define F_OPEN(name, mode) fopen((name), (mode))
|
# define F_OPEN(name, mode) fopen((name), (mode))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* functions */
|
/* functions */
|
||||||
|
|
||||||
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
|
||||||
# ifndef HAVE_VSNPRINTF
|
# ifndef HAVE_VSNPRINTF
|
||||||
# define HAVE_VSNPRINTF
|
# define HAVE_VSNPRINTF
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#if defined(__CYGWIN__)
|
#if defined(__CYGWIN__)
|
||||||
# ifndef HAVE_VSNPRINTF
|
# ifndef HAVE_VSNPRINTF
|
||||||
# define HAVE_VSNPRINTF
|
# define HAVE_VSNPRINTF
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef HAVE_VSNPRINTF
|
#ifndef HAVE_VSNPRINTF
|
||||||
# ifdef MSDOS
|
# ifdef MSDOS
|
||||||
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
/* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
|
||||||
but for now we just assume it doesn't. */
|
but for now we just assume it doesn't. */
|
||||||
# define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
# endif
|
# endif
|
||||||
# ifdef __TURBOC__
|
# ifdef __TURBOC__
|
||||||
# define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
# endif
|
# endif
|
||||||
# ifdef WIN32
|
# ifdef WIN32
|
||||||
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
/* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
|
||||||
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
# if !defined(vsnprintf) && !defined(NO_vsnprintf)
|
||||||
# define vsnprintf _vsnprintf
|
# define vsnprintf _vsnprintf
|
||||||
# endif
|
# endif
|
||||||
# endif
|
# endif
|
||||||
# ifdef __SASC
|
# ifdef __SASC
|
||||||
# define NO_vsnprintf
|
# define NO_vsnprintf
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef VMS
|
||||||
#ifdef HAVE_STRERROR
|
# define NO_vsnprintf
|
||||||
extern char *strerror OF((int));
|
#endif
|
||||||
# define zstrerror(errnum) strerror(errnum)
|
|
||||||
#else
|
#ifdef HAVE_STRERROR
|
||||||
# define zstrerror(errnum) ""
|
# ifndef VMS
|
||||||
#endif
|
extern char *strerror OF((int));
|
||||||
|
# endif
|
||||||
#if defined(pyr)
|
# define zstrerror(errnum) strerror(errnum)
|
||||||
# define NO_MEMCPY
|
#else
|
||||||
#endif
|
# define zstrerror(errnum) ""
|
||||||
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
#endif
|
||||||
/* Use our own functions for small and medium model with MSC <= 5.0.
|
|
||||||
* You may have to use the same strategy for Borland C (untested).
|
#if defined(pyr)
|
||||||
* The __SC__ check is for Symantec.
|
# define NO_MEMCPY
|
||||||
*/
|
#endif
|
||||||
# define NO_MEMCPY
|
#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
|
||||||
#endif
|
/* Use our own functions for small and medium model with MSC <= 5.0.
|
||||||
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
* You may have to use the same strategy for Borland C (untested).
|
||||||
# define HAVE_MEMCPY
|
* The __SC__ check is for Symantec.
|
||||||
#endif
|
*/
|
||||||
#ifdef HAVE_MEMCPY
|
# define NO_MEMCPY
|
||||||
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
#endif
|
||||||
# define zmemcpy _fmemcpy
|
#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
|
||||||
# define zmemcmp _fmemcmp
|
# define HAVE_MEMCPY
|
||||||
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
#endif
|
||||||
# else
|
#ifdef HAVE_MEMCPY
|
||||||
# define zmemcpy memcpy
|
# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
|
||||||
# define zmemcmp memcmp
|
# define zmemcpy _fmemcpy
|
||||||
# define zmemzero(dest, len) memset(dest, 0, len)
|
# define zmemcmp _fmemcmp
|
||||||
# endif
|
# define zmemzero(dest, len) _fmemset(dest, 0, len)
|
||||||
#else
|
# else
|
||||||
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
# define zmemcpy memcpy
|
||||||
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
# define zmemcmp memcmp
|
||||||
extern void zmemzero OF((Bytef* dest, uInt len));
|
# define zmemzero(dest, len) memset(dest, 0, len)
|
||||||
#endif
|
# endif
|
||||||
|
#else
|
||||||
/* Diagnostic functions */
|
extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
|
||||||
#ifdef DEBUG
|
extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
|
||||||
# include <stdio.h>
|
extern void zmemzero OF((Bytef* dest, uInt len));
|
||||||
extern int z_verbose;
|
#endif
|
||||||
extern void z_error OF((char *m));
|
|
||||||
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
/* Diagnostic functions */
|
||||||
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
#ifdef DEBUG
|
||||||
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
# include <stdio.h>
|
||||||
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
extern int z_verbose;
|
||||||
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
extern void z_error OF((char *m));
|
||||||
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
|
||||||
#else
|
# define Trace(x) {if (z_verbose>=0) fprintf x ;}
|
||||||
# define Assert(cond,msg)
|
# define Tracev(x) {if (z_verbose>0) fprintf x ;}
|
||||||
# define Trace(x)
|
# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
|
||||||
# define Tracev(x)
|
# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
|
||||||
# define Tracevv(x)
|
# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
|
||||||
# define Tracec(c,x)
|
#else
|
||||||
# define Tracecv(c,x)
|
# define Assert(cond,msg)
|
||||||
#endif
|
# define Trace(x)
|
||||||
|
# define Tracev(x)
|
||||||
|
# define Tracevv(x)
|
||||||
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
# define Tracec(c,x)
|
||||||
void zcfree OF((voidpf opaque, voidpf ptr));
|
# define Tracecv(c,x)
|
||||||
|
#endif
|
||||||
#define ZALLOC(strm, items, size) \
|
|
||||||
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
|
||||||
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
|
||||||
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
void zcfree OF((voidpf opaque, voidpf ptr));
|
||||||
|
|
||||||
#endif /* ZUTIL_H */
|
#define ZALLOC(strm, items, size) \
|
||||||
|
(*((strm)->zalloc))((strm)->opaque, (items), (size))
|
||||||
|
#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
|
||||||
|
#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
|
||||||
|
|
||||||
|
#endif /* ZUTIL_H */
|
||||||
|
|
Loading…
Reference in a new issue