zlib的应用

摘要:
defined(_WIN32))&&(!defined(WIN32))&&(!

主要分析应用的demo,有空再分析底层实现

官方demo位于zlib-1.2.11contribminizip

对官方代码的分析

zlib的应用第1张zlib的应用第2张
/*miniunz.c
   Version 1.1, February 14h, 2010
   sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html)

         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html)

         Modifications of Unzip for Zip64
         Copyright (C) 2007-2008 Even Rouault

         Modifications for Zip64 support on both zip and unzip
         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com)
*/

#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))#ifndef __USE_FILE_OFFSET64
                #define __USE_FILE_OFFSET64
        #endif#ifndef __USE_LARGEFILE64
                #define __USE_LARGEFILE64
        #endif#ifndef _LARGEFILE64_SOURCE
                #define _LARGEFILE64_SOURCE
        #endif#ifndef _FILE_OFFSET_BIT
                #define _FILE_OFFSET_BIT 64
        #endif
#endif
#ifdef __APPLE__
//In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
#define FTELLO_FUNC(stream) ftello(stream)
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
#else
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
#define FTELLO_FUNC(stream) ftello64(stream)
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
#endif

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <errno.h>#include <fcntl.h>
#ifdef _WIN32
# include <direct.h># include <io.h>
#else# include <unistd.h># include <utime.h>
#endif

#include "unzip.h"

#define CASESENSITIVITY (0)
#define WRITEBUFFERSIZE (8192)
#define MAXFILENAME (256)
#ifdef _WIN32
#define USEWIN32IOAPI#include "iowin32.h"
#endif
/*mini unzip, demo of unzip package

  usage :
  Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]

  list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
    if it exists
*/


/*change_file_date : change the date/time of a file
    filename : the filename of the file where date/time must be modified
    dosdate : the new date at the MSDos format (4 bytes)
    tmu_date : the SAME new date at the tm_unz format */
voidchange_file_date(filename,dosdate,tmu_date)
    const char *filename;
    uLong dosdate;
    tm_unz tmu_date;
{
#ifdef _WIN32
  HANDLE hFile;
  FILETIME ftm,ftLocal,ftCreate,ftLastAcc,ftLastWrite;

  hFile = CreateFileA(filename,GENERIC_READ |GENERIC_WRITE,
                      0,NULL,OPEN_EXISTING,0,NULL);
  GetFileTime(hFile,&ftCreate,&ftLastAcc,&ftLastWrite);
  DosDateTimeToFileTime((WORD)(dosdate>>16),(WORD)dosdate,&ftLocal);
  LocalFileTimeToFileTime(&ftLocal,&ftm);
  SetFileTime(hFile,&ftm,&ftLastAcc,&ftm);
  CloseHandle(hFile);
#else#ifdef unix ||__APPLE__
  structutimbuf ut;
  structtm newdate;
  newdate.tm_sec =tmu_date.tm_sec;
  newdate.tm_min=tmu_date.tm_min;
  newdate.tm_hour=tmu_date.tm_hour;
  newdate.tm_mday=tmu_date.tm_mday;
  newdate.tm_mon=tmu_date.tm_mon;
  if (tmu_date.tm_year > 1900)
      newdate.tm_year=tmu_date.tm_year - 1900;
  elsenewdate.tm_year=tmu_date.tm_year ;
  newdate.tm_isdst=-1;

  ut.actime=ut.modtime=mktime(&newdate);
  utime(filename,&ut);
#endif
#endif}


/*mymkdir and change_file_date are not 100 % portable
   As I don't know well Unix, I wait feedback for the unix portion */

intmymkdir(dirname)
    const char*dirname;
{
    int ret=0;
#ifdef _WIN32
    ret =_mkdir(dirname);
#elif unixret = mkdir (dirname,0775);
#elif __APPLE__ret = mkdir (dirname,0775);
#endif
    returnret;
}

intmakedir (newdir)
    char *newdir;
{
  char *buffer ;
  char *p;
  int  len = (int)strlen(newdir);

  if (len <= 0)
    return 0;

  buffer = (char*)malloc(len+1);
        if (buffer==NULL)
        {
                printf("Error allocating memory
");
                returnUNZ_INTERNALERROR;
        }
  strcpy(buffer,newdir);

  if (buffer[len-1] == '/') {
    buffer[len-1] = '

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇GNU长选项命令行解析getopt_long()(PHP)redis String(字符串)操作下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

pytest框架+allure2框架的基本使用(2019-09-03更新)

前提准备: pip安装allure-pytest、pytest和allure-python-commons包,安装过程如下图: pip install allure-pytest pip install pytest pip install allure-python-commons 安装成功如下: allure --version 2.12.1 py...

关于Java类Calendar做统计时 获取日期的一些常见操作

1、获取本周的周一到周日 //通过调整日历,获得本天所属周的周一和周日 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Calendar cal=new GregorianCalendar(); cal.setFirstDayOfWeek(Calendar.MONDAY); ca...

Delphi与各数据库数据类型比较

Delphi数据类型与各数据库数据类型对比如下表,如有具体说明见表中脚注: DelphiType OracleTypes SQLServerTypes MySQLTypes[1] InterBaseTypes PostgreSQLTypes SQLiteTypes ftSmallint NUMBER(p,0)[2](p<5) SMALLINT...

【Python之路】特别篇--ECMA对象、DOM对象、BOM对象

ECMA对象从传统意义上来说,ECMAScript 并不真正具有类。事实上,除了说明不存在类,在 ECMA-262 中根本没有出现“类”这个词。 ECMAScript 定义了“对象定义”,逻辑上等价于其他程序设计语言中的类。 var o = new Object(); 对象的概念与分类: 由ECMAScript定义的本地对象.独立于宿主环境的 ECMAS...

zlib用法

uses   zlib; //将Src使用Zlib压缩后存入Dst当中 procedure PackStream(const Src:TStream; Dst:TStream); var   CompStream: TCompressionStream; begin   //增加“断言”以防止输入参数有误   Assert(Src <&g...

LocalDate获取当天,本月第一天,本月最后一天,今年第一天,今年最后一天

使用jdk1.8的LocalDate获取当天,本月第一天,本月最后一天,今年第一天,今年最后一天 LocalDate localDate = LocalDate.now(); //今天 Date day = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).to...