/* minigzip.c -- simulate gzip using the zlib compression library
* Copyright (C) 1995-2006, 2010, 2011 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/*
* minigzip is a minimal implementation of the gzip utility. This is
* only an example of using zlib and isn't meant to replace the
* full-featured gzip. No attempt is made to deal with file systems
* limiting names to 14 or 8+3 characters, etc... Error checking is
* very limited. So use minigzip only for testing; use gzip for the
* real thing. On MSDOS, use only on file names without extension
* or in pipe mode.
*/
/* @(#) $Id$ */
#include "zlib.h"
#include <stdio.h>
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
#ifdef USE_MMAP
#endif
# include <fcntl.h>
# include <io.h>
# ifdef UNDER_CE
# include <stdlib.h>
# endif
#else
#endif
#ifdef VMS
#endif
#ifdef RISCOS
#endif
# include <unix.h> /* for fileno */
#endif
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
#endif
#endif
#if defined(UNDER_CE)
# include <windows.h>
/* Map the Windows error number in ERROR to a locale-dependent error
message string and return a pointer to it. Typically, the values
for ERROR come from GetLastError.
The string pointed to shall not be modified by the application,
but may be overwritten by a subsequent call to strwinerror
The strwinerror function does not change the current setting
of GetLastError. */
{
NULL,
0, /* Default language */
0,
NULL);
if (chars != 0) {
/* If there is an \r\n appended, zap it. */
if (chars >= 2
chars -= 2;
}
}
}
else {
}
return buf;
}
static void pwinerror (s)
const char *s;
{
if (s && *s)
else
}
#endif /* UNDER_CE */
#ifndef GZ_SUFFIX
#endif
#ifdef MAXSEG_64K
# define local static
/* Needed for systems with limitation on stack size. */
#else
# define local
#endif
#ifdef Z_SOLO
/* for Z_SOLO, create simplified gz* functions using deflate and inflate */
#if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
# include <unistd.h> /* for unlink() */
#endif
void *myalloc(q, n, m)
void *q;
unsigned n, m;
{
q = Z_NULL;
return calloc(n, m);
}
void myfree(q, p)
void *q, *p;
{
q = Z_NULL;
free(p);
}
typedef struct gzFile_s {
int write;
int err;
char *msg;
} *gzFile;
const char *path;
const char *mode;
{
}
int fd;
const char *mode;
{
}
const char *path;
int fd;
const char *mode;
{
int ret;
return NULL;
else {
}
return NULL;
}
return NULL;
}
return gz;
}
const void *buf;
unsigned len;
{
return 0;
do {
return len;
}
void *buf;
unsigned len;
{
int ret;
unsigned got;
return 0;
return 0;
do {
if (got == 0)
break;
if (ret == Z_DATA_ERROR) {
return 0;
}
if (ret == Z_STREAM_END)
}
{
return Z_STREAM_ERROR;
do {
}
else
return Z_OK;
}
int *err;
{
}
#endif
char *prog;
#ifdef USE_MMAP
#endif
/* ===========================================================================
* Display error message and exit
*/
const char *msg;
{
exit(1);
}
/* ===========================================================================
* Compress input to output then close both files.
*/
{
int len;
int err;
#ifdef USE_MMAP
/* Try first compressing with mmap. If mmap fails (minigzip used in a
* pipe), use the normal fread loop.
*/
#endif
for (;;) {
perror("fread");
exit(1);
}
if (len == 0) break;
}
}
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
/* Try compressing the input file at once using mmap. Return Z_OK if
* if success, Z_ERRNO otherwise.
*/
{
int len;
int err;
/* Determine the size of the file, needed for mmap: */
/* Now do the actual mmap: */
/* Compress the whole file at once: */
return Z_OK;
}
#endif /* USE_MMAP */
/* ===========================================================================
* Uncompress input to output then close both files.
*/
{
int len;
int err;
for (;;) {
if (len == 0) break;
error("failed fwrite");
}
}
}
/* ===========================================================================
* Compress the given file: create a corresponding .gz file and remove the
* original.
*/
char *file;
char *mode;
{
exit(1);
}
exit(1);
}
exit(1);
}
}
/* ===========================================================================
* Uncompress the given file and remove the original.
*/
char *file;
{
exit(1);
}
} else {
}
exit(1);
}
exit(1);
}
}
/* ===========================================================================
* Usage: minigzip [-c] [-d] [-f] [-h] [-r] [-1 to -9] [files...]
* -c : write to standard output
* -d : decompress
* -f : compress with Z_FILTERED
* -h : compress with Z_HUFFMAN_ONLY
* -r : compress with Z_RLE
* -1 to -9 : compression level
*/
int argc;
char *argv[];
{
int copyout = 0;
int uncompr = 0;
if (bname)
bname++;
else
uncompr = 1;
while (argc > 0) {
copyout = 1;
uncompr = 1;
(*argv)[2] == 0)
else
break;
}
outmode[3] = 0;
if (argc == 0) {
if (uncompr) {
} else {
}
} else {
if (copyout) {
}
do {
if (uncompr) {
if (copyout) {
else
} else {
}
} else {
if (copyout) {
} else {
}
} else {
}
}
}
return 0;
}