cabinet: Import zlib deflate code.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-11-25 13:30:27 +01:00
parent 3c31cc5836
commit 03e9bf95be
4 changed files with 3138 additions and 11 deletions

View File

@ -1,10 +1,9 @@
MODULE = cabinet.dll MODULE = cabinet.dll
IMPORTLIB = cabinet IMPORTLIB = cabinet
EXTRAINCL = $(Z_CFLAGS)
EXTRALIBS = $(Z_LIBS)
C_SRCS = \ C_SRCS = \
cabinet_main.c \ cabinet_main.c \
deflate.c \
fci.c \ fci.c \
fdi.c fdi.c

2974
dlls/cabinet/deflate.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -38,15 +38,13 @@ There is still some work to be done:
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef HAVE_ZLIB
# include <zlib.h>
#endif
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winerror.h" #include "winerror.h"
#include "winternl.h" #include "winternl.h"
#include "fci.h" #include "fci.h"
#include "zlib.h"
#include "cabinet.h" #include "cabinet.h"
#include "wine/list.h" #include "wine/list.h"
#include "wine/debug.h" #include "wine/debug.h"
@ -909,8 +907,6 @@ static cab_UWORD compress_NONE( FCI_Int *fci )
return fci->cdata_in; return fci->cdata_in;
} }
#ifdef HAVE_ZLIB
static void *zalloc( void *opaque, unsigned int items, unsigned int size ) static void *zalloc( void *opaque, unsigned int items, unsigned int size )
{ {
FCI_Int *fci = opaque; FCI_Int *fci = opaque;
@ -947,8 +943,6 @@ static cab_UWORD compress_MSZIP( FCI_Int *fci )
return stream.total_out + 2; return stream.total_out + 2;
} }
#endif /* HAVE_ZLIB */
/*********************************************************************** /***********************************************************************
* FCICreate (CABINET.10) * FCICreate (CABINET.10)
@ -1421,11 +1415,9 @@ BOOL __cdecl FCIAddFile(
switch (typeCompress) switch (typeCompress)
{ {
case tcompTYPE_MSZIP: case tcompTYPE_MSZIP:
#ifdef HAVE_ZLIB
p_fci_internal->compression = tcompTYPE_MSZIP; p_fci_internal->compression = tcompTYPE_MSZIP;
p_fci_internal->compress = compress_MSZIP; p_fci_internal->compress = compress_MSZIP;
break; break;
#endif
default: default:
FIXME( "compression %x not supported, defaulting to none\n", typeCompress ); FIXME( "compression %x not supported, defaulting to none\n", typeCompress );
/* fall through */ /* fall through */

162
dlls/cabinet/zlib.h Normal file
View File

@ -0,0 +1,162 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
* version 1.2.11, January 15th, 2017
*
* Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*
* Jean-loup Gailly Mark Adler
* jloup@gzip.org madler@alumni.caltech.edu
*/
#ifndef ZLIB_H
#define ZLIB_H
#include "windef.h"
#undef FAR
#define FAR
#define z_const const
typedef unsigned char Byte; /* 8 bits */
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte FAR Bytef;
typedef void FAR *voidpf;
typedef char FAR charf;
typedef int FAR intf;
typedef unsigned char uch;
typedef uch FAR uchf;
typedef unsigned short ush;
typedef ush FAR ushf;
typedef unsigned long ulg;
typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func)(voidpf opaque, voidpf address);
struct internal_state;
typedef struct z_stream_s {
z_const Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total number of input bytes read so far */
Bytef *next_out; /* next output byte will go here */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total number of bytes output so far */
z_const char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: binary or text
for deflate, or the decoding state for inflate */
uLong adler; /* Adler-32 or CRC-32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
/*
gzip header information passed to and from zlib routines. See RFC 1952
for more details on the meanings of these fields.
*/
typedef struct gz_header_s {
int text; /* true if compressed data believed to be text */
uLong time; /* modification time */
int xflags; /* extra flags (not used when writing a gzip file) */
int os; /* operating system */
Bytef *extra; /* pointer to extra field or Z_NULL if none */
uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
uInt extra_max; /* space at extra (only when reading header) */
Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
uInt name_max; /* space at name (only when reading header) */
Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
uInt comm_max; /* space at comment (only when reading header) */
int hcrc; /* true if there was or will be a header crc */
int done; /* true when done reading gzip header (not used
when writing a gzip file) */
} gz_header;
typedef gz_header FAR *gz_headerp;
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
#define Z_BLOCK 5
#define Z_TREES 6
/* Allowed flush values; see deflate() and inflate() below for details */
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative values
* are errors, positive values are used for special but normal events.
*/
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_RLE 3
#define Z_FIXED 4
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
#define Z_BINARY 0
#define Z_TEXT 1
#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2
/* Possible values of the data_type field for deflate() */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define MAX_WBITS 15 /* 32K LZ77 window */
#define MAX_MEM_LEVEL 9
extern int inflateInit(z_streamp strm) DECLSPEC_HIDDEN;
extern int inflateInit2(z_streamp strm, int windowBits) DECLSPEC_HIDDEN;
extern int inflate(z_streamp strm, int flush) DECLSPEC_HIDDEN;
extern int inflateEnd(z_streamp strm) DECLSPEC_HIDDEN;
extern int deflateInit(z_streamp strm, int level) DECLSPEC_HIDDEN;
extern int deflateInit2(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy) DECLSPEC_HIDDEN;
extern int deflate(z_streamp strm, int flush) DECLSPEC_HIDDEN;
extern int deflateEnd(z_streamp strm) DECLSPEC_HIDDEN;
#endif /* ZLIB_H */