亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gzio.cpp

?? 一個C語言實現的壓縮解壓的工具代碼
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/* gzio.c -- IO on .gz files
 * Copyright (C) 1995-1998 Jean-loup Gailly.
 * For conditions of distribution and use, see copyright notice in zlib.h
 *
 * Compile this file with -DNO_DEFLATE to avoid the compression code.
 */

/* @(#) $Id$ */
#include "stdafx.h"
#include <stdio.h>

#include "zutil.h"

struct internal_state {int dummy;}; /* for buggy compilers */

#ifndef Z_BUFSIZE
#  ifdef MAXSEG_64K
#    define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
#  else
#    define Z_BUFSIZE 16384
#  endif
#endif
#ifndef Z_PRINTF_BUFSIZE
#  define Z_PRINTF_BUFSIZE 4096
#endif

#define ALLOC(size) malloc(size)
#define TRYFREE(p) {if (p) free(p);}

static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */

/* gzip flag byte */
#define ASCII_FLAG   0x01 /* bit 0 set: file probably ascii text */
#define HEAD_CRC     0x02 /* bit 1 set: header CRC present */
#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
#define COMMENT      0x10 /* bit 4 set: file comment present */
#define RESERVED     0xE0 /* bits 5..7: reserved */

typedef struct gz_stream {
    z_stream stream;
    int      z_err;   /* error code for last stream operation */
    int      z_eof;   /* set if end of input file */
    FILE     *file;   /* .gz file */
    Byte     *inbuf;  /* input buffer */
    Byte     *outbuf; /* output buffer */
    uLong    crc;     /* crc32 of uncompressed data */
    char     *msg;    /* error message */
    char     *path;   /* path name for debugging only */
    int      transparent; /* 1 if input file is not a .gz file */
    char     mode;    /* 'w' or 'r' */
    long     startpos; /* start of compressed data in file (header skipped) */
} gz_stream;


local gzFile gz_open      OF((const char *path, const char *mode, int  fd));
local int do_flush        OF((gzFile file, int flush));
local int    get_byte     OF((gz_stream *s));
local void   check_header OF((gz_stream *s));
local int    destroy      OF((gz_stream *s));
local void   putLong      OF((FILE *file, uLong x));
local uLong  getLong      OF((gz_stream *s));

/* ===========================================================================
     Opens a gzip (.gz) file for reading or writing. The mode parameter
   is as in fopen ("rb" or "wb"). The file is given either by file descriptor
   or path name (if fd == -1).
     gz_open return NULL if the file could not be opened or if there was
   insufficient memory to allocate the (de)compression state; errno
   can be checked to distinguish the two cases (if errno is zero, the
   zlib error is Z_MEM_ERROR).
*/
local gzFile gz_open ( const char *path,
    const char *mode,
    int  fd)
   
{
    int err;
    int level = Z_DEFAULT_COMPRESSION; /* compression level */
    int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
    char *p = (char*)mode;
    gz_stream *s;
    char fmode[80]; /* copy of mode, without the compression level */
    char *m = fmode;

    if (!path || !mode) return Z_NULL;

    s = (gz_stream *)ALLOC(sizeof(gz_stream));
    if (!s) return Z_NULL;

    s->stream.zalloc = (alloc_func)0;
    s->stream.zfree = (free_func)0;
    s->stream.opaque = (voidpf)0;
    s->stream.next_in = s->inbuf = Z_NULL;
    s->stream.next_out = s->outbuf = Z_NULL;
    s->stream.avail_in = s->stream.avail_out = 0;
    s->file = NULL;
    s->z_err = Z_OK;
    s->z_eof = 0;
    s->crc = crc32(0L, Z_NULL, 0);
    s->msg = NULL;
    s->transparent = 0;

    s->path = (char*)ALLOC(strlen(path)+1);
    if (s->path == NULL) {
        return destroy(s), (gzFile)Z_NULL;
    }
    strcpy(s->path, path); /* do this early for debugging */

    s->mode = '\0';
    do {
        if (*p == 'r') s->mode = 'r';
        if (*p == 'w' || *p == 'a') s->mode = 'w';
        if (*p >= '0' && *p <= '9') {
	    level = *p - '0';
	} else if (*p == 'f') {
	  strategy = Z_FILTERED;
	} else if (*p == 'h') {
	  strategy = Z_HUFFMAN_ONLY;
	} else {
	    *m++ = *p; /* copy the mode */
	}
    } while (*p++ && m != fmode + sizeof(fmode));
    if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
    
    if (s->mode == 'w') {
#ifdef NO_DEFLATE
        err = Z_STREAM_ERROR;
#else
        err = deflateInit2(&(s->stream), level,
                           Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
        /* windowBits is passed < 0 to suppress zlib header */

        s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
#endif
        if (err != Z_OK || s->outbuf == Z_NULL) {
            return destroy(s), (gzFile)Z_NULL;
        }
    } else {
        s->stream.next_in  = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);

        err = inflateInit2(&(s->stream), -MAX_WBITS);
        /* windowBits is passed < 0 to tell that there is no zlib header.
         * Note that in this case inflate *requires* an extra "dummy" byte
         * after the compressed stream in order to complete decompression and
         * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
         * present after the compressed stream.
         */
        if (err != Z_OK || s->inbuf == Z_NULL) {
            return destroy(s), (gzFile)Z_NULL;
        }
    }
    s->stream.avail_out = Z_BUFSIZE;

    errno = 0;
    s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);

    if (s->file == NULL) {
        return destroy(s), (gzFile)Z_NULL;
    }
    if (s->mode == 'w') {
        /* Write a very simple .gz header:
         */
        fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
             Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
	s->startpos = 10L;
	/* We use 10L instead of ftell(s->file) to because ftell causes an
         * fflush on some systems. This version of the library doesn't use
         * startpos anyway in write mode, so this initialization is not
         * necessary.
         */
    } else {
	check_header(s); /* skip the .gz header */
	s->startpos = (ftell(s->file) - s->stream.avail_in);
    }
    
    return (gzFile)s;
}

/* ===========================================================================
     Opens a gzip (.gz) file for reading or writing.
*/
gzFile ZEXPORT gzopen (    const char *path,
    const char *mode)

{
    return gz_open (path, mode, -1);
}

/* ===========================================================================
     Associate a gzFile with the file descriptor fd. fd is not dup'ed here
   to mimic the behavio(u)r of fdopen.
*/
gzFile ZEXPORT gzdopen (    int fd,
    const char *mode)

{
    char name[20];

    if (fd < 0) return (gzFile)Z_NULL;
    sprintf(name, "<fd:%d>", fd); /* for debugging */

    return gz_open (name, mode, fd);
}

/* ===========================================================================
 * Update the compression level and strategy
 */
int ZEXPORT gzsetparams (  gzFile file,
    int level,
    int strategy)
  
{
    gz_stream *s = (gz_stream*)file;

    if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;

    /* Make room to allow flushing */
    if (s->stream.avail_out == 0) {

	s->stream.next_out = s->outbuf;
	if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
	    s->z_err = Z_ERRNO;
	}
	s->stream.avail_out = Z_BUFSIZE;
    }

    return deflateParams (&(s->stream), level, strategy);
}

/* ===========================================================================
     Read a byte from a gz_stream; update next_in and avail_in. Return EOF
   for end of file.
   IN assertion: the stream s has been sucessfully opened for reading.
*/
local int get_byte(gz_stream *s)
{
    if (s->z_eof) return EOF;
    if (s->stream.avail_in == 0) {
	errno = 0;
	s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
	if (s->stream.avail_in == 0) {
	    s->z_eof = 1;
	    if (ferror(s->file)) s->z_err = Z_ERRNO;
	    return EOF;
	}
	s->stream.next_in = s->inbuf;
    }
    s->stream.avail_in--;
    return *(s->stream.next_in)++;
}

/* ===========================================================================
      Check the gzip header of a gz_stream opened for reading. Set the stream
    mode to transparent if the gzip magic header is not present; set s->err
    to Z_DATA_ERROR if the magic header is present but the rest of the header
    is incorrect.
    IN assertion: the stream s has already been created sucessfully;
       s->stream.avail_in is zero for the first time, but may be non-zero
       for concatenated .gz files.
*/
local void check_header(  gz_stream *s)
  
{
    int method; /* method byte */
    int flags;  /* flags byte */
    uInt len;
    int c;

    /* Check the gzip magic header */
    for (len = 0; len < 2; len++) {
	c = get_byte(s);
	if (c != gz_magic[len]) {
	    if (len != 0) s->stream.avail_in++, s->stream.next_in--;
	    if (c != EOF) {
		s->stream.avail_in++, s->stream.next_in--;
		s->transparent = 1;
	    }
	    s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
	    return;
	}
    }
    method = get_byte(s);
    flags = get_byte(s);
    if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
	s->z_err = Z_DATA_ERROR;
	return;
    }

    /* Discard time, xflags and OS code: */
    for (len = 0; len < 6; len++) (void)get_byte(s);

    if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
	len  =  (uInt)get_byte(s);
	len += ((uInt)get_byte(s))<<8;
	/* len is garbage if EOF but the loop below will quit anyway */
	while (len-- != 0 && get_byte(s) != EOF) ;
    }
    if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
	while ((c = get_byte(s)) != 0 && c != EOF) ;
    }
    if ((flags & COMMENT) != 0) {   /* skip the .gz file comment */
	while ((c = get_byte(s)) != 0 && c != EOF) ;
    }
    if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
	for (len = 0; len < 2; len++) (void)get_byte(s);
    }
    s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
}

 /* ===========================================================================
 * Cleanup then free the given gz_stream. Return a zlib error code.
   Try freeing in the reverse order of allocations.
 */
local int destroy ( gz_stream *s)
   
{
    int err = Z_OK;

    if (!s) return Z_STREAM_ERROR;

    TRYFREE(s->msg);

    if (s->stream.state != NULL) {
	if (s->mode == 'w') {
#ifdef NO_DEFLATE
	    err = Z_STREAM_ERROR;
#else
	    err = deflateEnd(&(s->stream));
#endif
	} else if (s->mode == 'r') {
	    err = inflateEnd(&(s->stream));
	}
    }
    if (s->file != NULL && fclose(s->file)) {
#ifdef ESPIPE
	if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
#endif
	    err = Z_ERRNO;
    }
    if (s->z_err < 0) err = s->z_err;

    TRYFREE(s->inbuf);
    TRYFREE(s->outbuf);
    TRYFREE(s->path);
    TRYFREE(s);
    return err;
}

/* ===========================================================================
     Reads the given number of uncompressed bytes from the compressed file.
   gzread returns the number of bytes actually read (0 for end of file).
*/
int ZEXPORT gzread (   gzFile file,
    voidp buf,
    unsigned len)
 
{
    gz_stream *s = (gz_stream*)file;
    Bytef *start = (Bytef*)buf; /* starting point for crc computation */
    Byte  *next_out; /* == stream.next_out but not forced far (for MSDOS) */

    if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;

    if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
    if (s->z_err == Z_STREAM_END) return 0;  /* EOF */

    next_out = (Byte*)buf;
    s->stream.next_out = (Bytef*)buf;
    s->stream.avail_out = len;

    while (s->stream.avail_out != 0) {

	if (s->transparent) {
	    /* Copy first the lookahead bytes: */
	    uInt n = s->stream.avail_in;
	    if (n > s->stream.avail_out) n = s->stream.avail_out;
	    if (n > 0) {
		zmemcpy(s->stream.next_out, s->stream.next_in, n);
		next_out += n;
		s->stream.next_out = next_out;
		s->stream.next_in   += n;
		s->stream.avail_out -= n;
		s->stream.avail_in  -= n;
	    }
	    if (s->stream.avail_out > 0) {
		s->stream.avail_out -= fread(next_out, 1, s->stream.avail_out,
					     s->file);
	    }
	    len -= s->stream.avail_out;
	    s->stream.total_in  += (uLong)len;
	    s->stream.total_out += (uLong)len;
            if (len == 0) s->z_eof = 1;
	    return (int)len;
	}
        if (s->stream.avail_in == 0 && !s->z_eof) {

            errno = 0;
            s->stream.avail_in = fread(s->inbuf, 1, Z_BUFSIZE, s->file);
            if (s->stream.avail_in == 0) {
                s->z_eof = 1;
		if (ferror(s->file)) {
		    s->z_err = Z_ERRNO;
		    break;
		}
            }
            s->stream.next_in = s->inbuf;
        }
        s->z_err = inflate(&(s->stream), Z_NO_FLUSH);

	if (s->z_err == Z_STREAM_END) {
	    /* Check CRC and original size */
	    s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
	    start = s->stream.next_out;

	    if (getLong(s) != s->crc) {
		s->z_err = Z_DATA_ERROR;
	    } else {
	        (void)getLong(s);
                /* The uncompressed length returned by above getlong() may
                 * be different from s->stream.total_out) in case of
		 * concatenated .gz files. Check for such files:
		 */
		check_header(s);
		if (s->z_err == Z_OK) {
		    uLong total_in = s->stream.total_in;
		    uLong total_out = s->stream.total_out;

		    inflateReset(&(s->stream));
		    s->stream.total_in = total_in;
		    s->stream.total_out = total_out;
		    s->crc = crc32(0L, Z_NULL, 0);
		}
	    }
	}
	if (s->z_err != Z_OK || s->z_eof) break;
    }
    s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
精品免费日韩av| 成人app软件下载大全免费| 欧美撒尿777hd撒尿| 亚洲高清在线视频| 欧美男人的天堂一二区| 男女视频一区二区| 精品理论电影在线| 国产传媒欧美日韩成人| 亚洲视频免费在线观看| 欧美三级中文字幕| 黄网站免费久久| 国产精品欧美久久久久无广告| 色综合久久综合网97色综合 | 国产亚洲福利社区一区| 成人在线一区二区三区| 亚洲精品免费在线| 精品久久人人做人人爽| www.av精品| 日韩激情视频在线观看| 久久精品在这里| 在线观看国产精品网站| 久久国产综合精品| 亚洲欧美日韩中文播放| 欧美一二三区在线| 99久久婷婷国产综合精品| 午夜精品福利久久久| 国产午夜精品久久久久久久| 日本福利一区二区| 国产自产2019最新不卡| 一区二区成人在线| 国产喷白浆一区二区三区| 欧美日韩中文国产| 国产成人三级在线观看| 石原莉奈在线亚洲三区| 国产精品免费人成网站| 欧美日韩视频在线观看一区二区三区 | 亚洲一区二区av在线| 日韩免费视频线观看| 91浏览器打开| 国产一区二区三区在线观看免费视频 | 国产自产2019最新不卡| 亚洲亚洲人成综合网络| 国产农村妇女毛片精品久久麻豆| 欧美日韩国产小视频| 99久久免费视频.com| 麻豆国产一区二区| 亚洲自拍与偷拍| 国产精品夫妻自拍| 欧美精品一区二区三区高清aⅴ| 色婷婷综合久久久中文一区二区| 韩国欧美一区二区| 日韩av高清在线观看| 亚洲精品国久久99热| 国产精品网友自拍| 精品88久久久久88久久久| 欧美色手机在线观看| 91免费在线播放| 国产精品99久久久久久宅男| 日韩va亚洲va欧美va久久| 亚洲综合精品自拍| 一区二区三区在线免费观看| 国产精品久久久久久久久免费樱桃 | 欧美日韩一区中文字幕| 色综合夜色一区| 粉嫩欧美一区二区三区高清影视| 蜜臀精品久久久久久蜜臀| 香蕉成人伊视频在线观看| 亚洲伦理在线免费看| 中文字幕一区二区日韩精品绯色| 国产欧美一区二区精品性色 | 欧美精品九九99久久| 色欧美日韩亚洲| 色香色香欲天天天影视综合网| 成人精品免费看| fc2成人免费人成在线观看播放| 国产成人99久久亚洲综合精品| 国产在线乱码一区二区三区| 免费观看日韩电影| 激情久久久久久久久久久久久久久久| 蜜臀99久久精品久久久久久软件| 日日摸夜夜添夜夜添精品视频| 日本美女视频一区二区| 日韩av电影天堂| 久久激情五月激情| 国产制服丝袜一区| 国v精品久久久网| 成人av在线播放网站| 91福利在线免费观看| 欧美日韩综合在线| 日韩视频免费直播| 久久免费偷拍视频| 中文字幕在线不卡一区| 一区二区三区在线观看欧美| 亚洲成人先锋电影| 美腿丝袜亚洲三区| 国产成人免费高清| 不卡av电影在线播放| 欧美性欧美巨大黑白大战| 欧美丰满少妇xxxbbb| 精品福利二区三区| 国产精品免费人成网站| 亚洲一区二区综合| 免费成人在线观看| 国产成人无遮挡在线视频| 日本伦理一区二区| 制服视频三区第一页精品| 欧美精品一区二区久久久| 亚洲欧美中日韩| 日韩—二三区免费观看av| 国产精品一级二级三级| 色婷婷综合久色| 欧美精品一区男女天堂| 中文字幕五月欧美| 美国av一区二区| 99久久99久久精品国产片果冻| 欧美精品日韩精品| 日本在线播放一区二区三区| 国产一区在线看| 欧美日韩在线三区| 国产精品视频一二三区 | 久久亚洲精华国产精华液| 亚洲免费高清视频在线| 激情欧美日韩一区二区| 日本二三区不卡| 国产欧美一二三区| 日韩高清中文字幕一区| 99久久婷婷国产精品综合| 精品久久久久久综合日本欧美| 亚洲欧洲综合另类在线| 国产精品一区二区果冻传媒| 欧美日韩精品系列| 中文字幕在线观看一区| 精一区二区三区| 欧美区一区二区三区| 亚洲精品中文在线观看| 国产成人在线观看| 欧美一级专区免费大片| 亚洲伦理在线免费看| 成人免费高清视频在线观看| 欧美不卡一区二区三区四区| 亚洲一区av在线| 91免费观看在线| 日本一区二区三区视频视频| 蜜臀久久久久久久| 欧美视频在线一区| 亚洲日本在线a| 92国产精品观看| 中文字幕 久热精品 视频在线| 久久不见久久见免费视频7| 欧美色欧美亚洲另类二区| 亚洲男人的天堂av| 99久久精品情趣| 国产精品免费观看视频| 国产成人免费在线视频| 久久综合av免费| 韩国欧美国产1区| 欧美一区二区三区白人| 五月天激情小说综合| 欧美在线免费观看亚洲| 一区二区三区高清| 色综合天天综合| 1024亚洲合集| av电影在线观看完整版一区二区| 国产欧美一区二区在线| 成人综合婷婷国产精品久久蜜臀| 久久天天做天天爱综合色| 国产真实乱偷精品视频免| 国产亚洲视频系列| 成人av资源在线| 亚洲免费观看在线视频| 色丁香久综合在线久综合在线观看| 亚洲精品视频在线观看免费| 日本大香伊一区二区三区| 亚洲国产中文字幕| 在线不卡中文字幕播放| 六月丁香婷婷色狠狠久久| 亚洲精品一区二区精华| 成人精品一区二区三区中文字幕| ...xxx性欧美| 欧美日韩一级大片网址| 日本在线播放一区二区三区| 久久午夜羞羞影院免费观看| 欧美日韩一本到| 精品一区二区在线视频| 国产午夜亚洲精品理论片色戒| av一区二区三区| 亚洲高清不卡在线| 欧美成人a∨高清免费观看| 成人一区二区三区在线观看| 中文字幕在线一区免费| 欧美视频一区在线观看| 麻豆精品精品国产自在97香蕉| 日本一区二区久久| 欧洲精品在线观看| 麻豆精品一区二区av白丝在线| 中文字幕免费观看一区| 欧美影院一区二区| 九九视频精品免费| 亚洲同性同志一二三专区| 91精品久久久久久久99蜜桃 |