kusano fc6ab3
/*
kusano fc6ab3
   minizip.c
kusano fc6ab3
   Version 1.1, February 14h, 2010
kusano fc6ab3
   sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
kusano fc6ab3
kusano fc6ab3
         Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
kusano fc6ab3
kusano fc6ab3
         Modifications of Unzip for Zip64
kusano fc6ab3
         Copyright (C) 2007-2008 Even Rouault
kusano fc6ab3
kusano fc6ab3
         Modifications for Zip64 support on both zip and unzip
kusano fc6ab3
         Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
kusano fc6ab3
*/
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
kusano fc6ab3
        #ifndef __USE_FILE_OFFSET64
kusano fc6ab3
                #define __USE_FILE_OFFSET64
kusano fc6ab3
        #endif
kusano fc6ab3
        #ifndef __USE_LARGEFILE64
kusano fc6ab3
                #define __USE_LARGEFILE64
kusano fc6ab3
        #endif
kusano fc6ab3
        #ifndef _LARGEFILE64_SOURCE
kusano fc6ab3
                #define _LARGEFILE64_SOURCE
kusano fc6ab3
        #endif
kusano fc6ab3
        #ifndef _FILE_OFFSET_BIT
kusano fc6ab3
                #define _FILE_OFFSET_BIT 64
kusano fc6ab3
        #endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#ifdef __APPLE__
kusano fc6ab3
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
kusano fc6ab3
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
kusano fc6ab3
#define FTELLO_FUNC(stream) ftello(stream)
kusano fc6ab3
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
kusano fc6ab3
#else
kusano fc6ab3
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
kusano fc6ab3
#define FTELLO_FUNC(stream) ftello64(stream)
kusano fc6ab3
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#include <stdio.h></stdio.h>
kusano fc6ab3
#include <stdlib.h></stdlib.h>
kusano fc6ab3
#include <string.h></string.h>
kusano fc6ab3
#include <time.h></time.h>
kusano fc6ab3
#include <errno.h></errno.h>
kusano fc6ab3
#include <fcntl.h></fcntl.h>
kusano fc6ab3
kusano fc6ab3
#ifdef _WIN32
kusano fc6ab3
# include <direct.h></direct.h>
kusano fc6ab3
# include <io.h></io.h>
kusano fc6ab3
#else
kusano fc6ab3
# include <unistd.h></unistd.h>
kusano fc6ab3
# include <utime.h></utime.h>
kusano fc6ab3
# include <sys types.h=""></sys>
kusano fc6ab3
# include <sys stat.h=""></sys>
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
#include "zip.h"
kusano fc6ab3
kusano fc6ab3
#ifdef _WIN32
kusano fc6ab3
        #define USEWIN32IOAPI
kusano fc6ab3
        #include "iowin32.h"
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
#define WRITEBUFFERSIZE (16384)
kusano fc6ab3
#define MAXFILENAME (256)
kusano fc6ab3
kusano fc6ab3
#ifdef _WIN32
kusano fc6ab3
uLong filetime(f, tmzip, dt)
kusano fc6ab3
    char *f;                /* name of file to get info on */
kusano fc6ab3
    tm_zip *tmzip;             /* return value: access, modific. and creation times */
kusano fc6ab3
    uLong *dt;             /* dostime */
kusano fc6ab3
{
kusano fc6ab3
  int ret = 0;
kusano fc6ab3
  {
kusano fc6ab3
      FILETIME ftLocal;
kusano fc6ab3
      HANDLE hFind;
kusano fc6ab3
      WIN32_FIND_DATAA ff32;
kusano fc6ab3
kusano fc6ab3
      hFind = FindFirstFileA(f,&ff32);
kusano fc6ab3
      if (hFind != INVALID_HANDLE_VALUE)
kusano fc6ab3
      {
kusano fc6ab3
        FileTimeToLocalFileTime(&(ff32.ftLastWriteTime),&ftLocal);
kusano fc6ab3
        FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0);
kusano fc6ab3
        FindClose(hFind);
kusano fc6ab3
        ret = 1;
kusano fc6ab3
      }
kusano fc6ab3
  }
kusano fc6ab3
  return ret;
kusano fc6ab3
}
kusano fc6ab3
#else
kusano fc6ab3
#ifdef unix || __APPLE__
kusano fc6ab3
uLong filetime(f, tmzip, dt)
kusano fc6ab3
    char *f;               /* name of file to get info on */
kusano fc6ab3
    tm_zip *tmzip;         /* return value: access, modific. and creation times */
kusano fc6ab3
    uLong *dt;             /* dostime */
kusano fc6ab3
{
kusano fc6ab3
  int ret=0;
kusano fc6ab3
  struct stat s;        /* results of stat() */
kusano fc6ab3
  struct tm* filedate;
kusano fc6ab3
  time_t tm_t=0;
kusano fc6ab3
kusano fc6ab3
  if (strcmp(f,"-")!=0)
kusano fc6ab3
  {
kusano fc6ab3
    char name[MAXFILENAME+1];
kusano fc6ab3
    int len = strlen(f);
kusano fc6ab3
    if (len > MAXFILENAME)
kusano fc6ab3
      len = MAXFILENAME;
kusano fc6ab3
kusano fc6ab3
    strncpy(name, f,MAXFILENAME-1);
kusano fc6ab3
    /* strncpy doesnt append the trailing NULL, of the string is too long. */
kusano fc6ab3
    name[ MAXFILENAME ] = '\0';
kusano fc6ab3
kusano fc6ab3
    if (name[len - 1] == '/')
kusano fc6ab3
      name[len - 1] = '\0';
kusano fc6ab3
    /* not all systems allow stat'ing a file with / appended */
kusano fc6ab3
    if (stat(name,&s)==0)
kusano fc6ab3
    {
kusano fc6ab3
      tm_t = s.st_mtime;
kusano fc6ab3
      ret = 1;
kusano fc6ab3
    }
kusano fc6ab3
  }
kusano fc6ab3
  filedate = localtime(&tm_t);
kusano fc6ab3
kusano fc6ab3
  tmzip->tm_sec  = filedate->tm_sec;
kusano fc6ab3
  tmzip->tm_min  = filedate->tm_min;
kusano fc6ab3
  tmzip->tm_hour = filedate->tm_hour;
kusano fc6ab3
  tmzip->tm_mday = filedate->tm_mday;
kusano fc6ab3
  tmzip->tm_mon  = filedate->tm_mon ;
kusano fc6ab3
  tmzip->tm_year = filedate->tm_year;
kusano fc6ab3
kusano fc6ab3
  return ret;
kusano fc6ab3
}
kusano fc6ab3
#else
kusano fc6ab3
uLong filetime(f, tmzip, dt)
kusano fc6ab3
    char *f;                /* name of file to get info on */
kusano fc6ab3
    tm_zip *tmzip;             /* return value: access, modific. and creation times */
kusano fc6ab3
    uLong *dt;             /* dostime */
kusano fc6ab3
{
kusano fc6ab3
    return 0;
kusano fc6ab3
}
kusano fc6ab3
#endif
kusano fc6ab3
#endif
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
int check_exist_file(filename)
kusano fc6ab3
    const char* filename;
kusano fc6ab3
{
kusano fc6ab3
    FILE* ftestexist;
kusano fc6ab3
    int ret = 1;
kusano fc6ab3
    ftestexist = FOPEN_FUNC(filename,"rb");
kusano fc6ab3
    if (ftestexist==NULL)
kusano fc6ab3
        ret = 0;
kusano fc6ab3
    else
kusano fc6ab3
        fclose(ftestexist);
kusano fc6ab3
    return ret;
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
void do_banner()
kusano fc6ab3
{
kusano fc6ab3
    printf("MiniZip 1.1, demo of zLib + MiniZip64 package, written by Gilles Vollant\n");
kusano fc6ab3
    printf("more info on MiniZip at http://www.winimage.com/zLibDll/minizip.html\n\n");
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
void do_help()
kusano fc6ab3
{
kusano fc6ab3
    printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
kusano fc6ab3
           "  -o  Overwrite existing file.zip\n" \
kusano fc6ab3
           "  -a  Append to existing file.zip\n" \
kusano fc6ab3
           "  -0  Store only\n" \
kusano fc6ab3
           "  -1  Compress faster\n" \
kusano fc6ab3
           "  -9  Compress better\n\n" \
kusano fc6ab3
           "  -j  exclude path. store only the file name.\n\n");
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
/* calculate the CRC32 of a file,
kusano fc6ab3
   because to encrypt a file, we need known the CRC32 of the file before */
kusano fc6ab3
int getFileCrc(const char* filenameinzip,void*buf,unsigned long size_buf,unsigned long* result_crc)
kusano fc6ab3
{
kusano fc6ab3
   unsigned long calculate_crc=0;
kusano fc6ab3
   int err=ZIP_OK;
kusano fc6ab3
   FILE * fin = FOPEN_FUNC(filenameinzip,"rb");
kusano fc6ab3
kusano fc6ab3
   unsigned long size_read = 0;
kusano fc6ab3
   unsigned long total_read = 0;
kusano fc6ab3
   if (fin==NULL)
kusano fc6ab3
   {
kusano fc6ab3
       err = ZIP_ERRNO;
kusano fc6ab3
   }
kusano fc6ab3
kusano fc6ab3
    if (err == ZIP_OK)
kusano fc6ab3
        do
kusano fc6ab3
        {
kusano fc6ab3
            err = ZIP_OK;
kusano fc6ab3
            size_read = (int)fread(buf,1,size_buf,fin);
kusano fc6ab3
            if (size_read < size_buf)
kusano fc6ab3
                if (feof(fin)==0)
kusano fc6ab3
            {
kusano fc6ab3
                printf("error in reading %s\n",filenameinzip);
kusano fc6ab3
                err = ZIP_ERRNO;
kusano fc6ab3
            }
kusano fc6ab3
kusano fc6ab3
            if (size_read>0)
kusano fc6ab3
                calculate_crc = crc32(calculate_crc,buf,size_read);
kusano fc6ab3
            total_read += size_read;
kusano fc6ab3
kusano fc6ab3
        } while ((err == ZIP_OK) && (size_read>0));
kusano fc6ab3
kusano fc6ab3
    if (fin)
kusano fc6ab3
        fclose(fin);
kusano fc6ab3
kusano fc6ab3
    *result_crc=calculate_crc;
kusano fc6ab3
    printf("file %s crc %lx\n", filenameinzip, calculate_crc);
kusano fc6ab3
    return err;
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
int isLargeFile(const char* filename)
kusano fc6ab3
{
kusano fc6ab3
  int largeFile = 0;
kusano fc6ab3
  ZPOS64_T pos = 0;
kusano fc6ab3
  FILE* pFile = FOPEN_FUNC(filename, "rb");
kusano fc6ab3
kusano fc6ab3
  if(pFile != NULL)
kusano fc6ab3
  {
kusano fc6ab3
    int n = FSEEKO_FUNC(pFile, 0, SEEK_END);
kusano fc6ab3
    pos = FTELLO_FUNC(pFile);
kusano fc6ab3
kusano fc6ab3
                printf("File : %s is %lld bytes\n", filename, pos);
kusano fc6ab3
kusano fc6ab3
    if(pos >= 0xffffffff)
kusano fc6ab3
     largeFile = 1;
kusano fc6ab3
kusano fc6ab3
                fclose(pFile);
kusano fc6ab3
  }
kusano fc6ab3
kusano fc6ab3
 return largeFile;
kusano fc6ab3
}
kusano fc6ab3
kusano fc6ab3
int main(argc,argv)
kusano fc6ab3
    int argc;
kusano fc6ab3
    char *argv[];
kusano fc6ab3
{
kusano fc6ab3
    int i;
kusano fc6ab3
    int opt_overwrite=0;
kusano fc6ab3
    int opt_compress_level=Z_DEFAULT_COMPRESSION;
kusano fc6ab3
    int opt_exclude_path=0;
kusano fc6ab3
    int zipfilenamearg = 0;
kusano fc6ab3
    char filename_try[MAXFILENAME+16];
kusano fc6ab3
    int zipok;
kusano fc6ab3
    int err=0;
kusano fc6ab3
    int size_buf=0;
kusano fc6ab3
    void* buf=NULL;
kusano fc6ab3
    const char* password=NULL;
kusano fc6ab3
kusano fc6ab3
kusano fc6ab3
    do_banner();
kusano fc6ab3
    if (argc==1)
kusano fc6ab3
    {
kusano fc6ab3
        do_help();
kusano fc6ab3
        return 0;
kusano fc6ab3
    }
kusano fc6ab3
    else
kusano fc6ab3
    {
kusano fc6ab3
        for (i=1;i
kusano fc6ab3
        {
kusano fc6ab3
            if ((*argv[i])=='-')
kusano fc6ab3
            {
kusano fc6ab3
                const char *p=argv[i]+1;
kusano fc6ab3
kusano fc6ab3
                while ((*p)!='\0')
kusano fc6ab3
                {
kusano fc6ab3
                    char c=*(p++);;
kusano fc6ab3
                    if ((c=='o') || (c=='O'))
kusano fc6ab3
                        opt_overwrite = 1;
kusano fc6ab3
                    if ((c=='a') || (c=='A'))
kusano fc6ab3
                        opt_overwrite = 2;
kusano fc6ab3
                    if ((c>='0') && (c<='9'))
kusano fc6ab3
                        opt_compress_level = c-'0';
kusano fc6ab3
                    if ((c=='j') || (c=='J'))
kusano fc6ab3
                        opt_exclude_path = 1;
kusano fc6ab3
kusano fc6ab3
                    if (((c=='p') || (c=='P')) && (i+1
kusano fc6ab3
                    {
kusano fc6ab3
                        password=argv[i+1];
kusano fc6ab3
                        i++;
kusano fc6ab3
                    }
kusano fc6ab3
                }
kusano fc6ab3
            }
kusano fc6ab3
            else
kusano fc6ab3
            {
kusano fc6ab3
                if (zipfilenamearg == 0)
kusano fc6ab3
                {
kusano fc6ab3
                    zipfilenamearg = i ;
kusano fc6ab3
                }
kusano fc6ab3
            }
kusano fc6ab3
        }
kusano fc6ab3
    }
kusano fc6ab3
kusano fc6ab3
    size_buf = WRITEBUFFERSIZE;
kusano fc6ab3
    buf = (void*)malloc(size_buf);
kusano fc6ab3
    if (buf==NULL)
kusano fc6ab3
    {
kusano fc6ab3
        printf("Error allocating memory\n");
kusano fc6ab3
        return ZIP_INTERNALERROR;
kusano fc6ab3
    }
kusano fc6ab3
kusano fc6ab3
    if (zipfilenamearg==0)
kusano fc6ab3
    {
kusano fc6ab3
        zipok=0;
kusano fc6ab3
    }
kusano fc6ab3
    else
kusano fc6ab3
    {
kusano fc6ab3
        int i,len;
kusano fc6ab3
        int dot_found=0;
kusano fc6ab3
kusano fc6ab3
        zipok = 1 ;
kusano fc6ab3
        strncpy(filename_try, argv[zipfilenamearg],MAXFILENAME-1);
kusano fc6ab3
        /* strncpy doesnt append the trailing NULL, of the string is too long. */
kusano fc6ab3
        filename_try[ MAXFILENAME ] = '\0';
kusano fc6ab3
kusano fc6ab3
        len=(int)strlen(filename_try);
kusano fc6ab3
        for (i=0;i
kusano fc6ab3
            if (filename_try[i]=='.')
kusano fc6ab3
                dot_found=1;
kusano fc6ab3
kusano fc6ab3
        if (dot_found==0)
kusano fc6ab3
            strcat(filename_try,".zip");
kusano fc6ab3
kusano fc6ab3
        if (opt_overwrite==2)
kusano fc6ab3
        {
kusano fc6ab3
            /* if the file don't exist, we not append file */
kusano fc6ab3
            if (check_exist_file(filename_try)==0)
kusano fc6ab3
                opt_overwrite=1;
kusano fc6ab3
        }
kusano fc6ab3
        else
kusano fc6ab3
        if (opt_overwrite==0)
kusano fc6ab3
            if (check_exist_file(filename_try)!=0)
kusano fc6ab3
            {
kusano fc6ab3
                char rep=0;
kusano fc6ab3
                do
kusano fc6ab3
                {
kusano fc6ab3
                    char answer[128];
kusano fc6ab3
                    int ret;
kusano fc6ab3
                    printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
kusano fc6ab3
                    ret = scanf("%1s",answer);
kusano fc6ab3
                    if (ret != 1)
kusano fc6ab3
                    {
kusano fc6ab3
                       exit(EXIT_FAILURE);
kusano fc6ab3
                    }
kusano fc6ab3
                    rep = answer[0] ;
kusano fc6ab3
                    if ((rep>='a') && (rep<='z'))
kusano fc6ab3
                        rep -= 0x20;
kusano fc6ab3
                }
kusano fc6ab3
                while ((rep!='Y') && (rep!='N') && (rep!='A'));
kusano fc6ab3
                if (rep=='N')
kusano fc6ab3
                    zipok = 0;
kusano fc6ab3
                if (rep=='A')
kusano fc6ab3
                    opt_overwrite = 2;
kusano fc6ab3
            }
kusano fc6ab3
    }
kusano fc6ab3
kusano fc6ab3
    if (zipok==1)
kusano fc6ab3
    {
kusano fc6ab3
        zipFile zf;
kusano fc6ab3
        int errclose;
kusano fc6ab3
#        ifdef USEWIN32IOAPI
kusano fc6ab3
        zlib_filefunc64_def ffunc;
kusano fc6ab3
        fill_win32_filefunc64A(&ffunc);
kusano fc6ab3
        zf = zipOpen2_64(filename_try,(opt_overwrite==2) ? 2 : 0,NULL,&ffunc);
kusano fc6ab3
#        else
kusano fc6ab3
        zf = zipOpen64(filename_try,(opt_overwrite==2) ? 2 : 0);
kusano fc6ab3
#        endif
kusano fc6ab3
kusano fc6ab3
        if (zf == NULL)
kusano fc6ab3
        {
kusano fc6ab3
            printf("error opening %s\n",filename_try);
kusano fc6ab3
            err= ZIP_ERRNO;
kusano fc6ab3
        }
kusano fc6ab3
        else
kusano fc6ab3
            printf("creating %s\n",filename_try);
kusano fc6ab3
kusano fc6ab3
        for (i=zipfilenamearg+1;(i
kusano fc6ab3
        {
kusano fc6ab3
            if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
kusano fc6ab3
                  ((argv[i][1]=='o') || (argv[i][1]=='O') ||
kusano fc6ab3
                   (argv[i][1]=='a') || (argv[i][1]=='A') ||
kusano fc6ab3
                   (argv[i][1]=='p') || (argv[i][1]=='P') ||
kusano fc6ab3
                   ((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
kusano fc6ab3
                  (strlen(argv[i]) == 2)))
kusano fc6ab3
            {
kusano fc6ab3
                FILE * fin;
kusano fc6ab3
                int size_read;
kusano fc6ab3
                const char* filenameinzip = argv[i];
kusano fc6ab3
                const char *savefilenameinzip;
kusano fc6ab3
                zip_fileinfo zi;
kusano fc6ab3
                unsigned long crcFile=0;
kusano fc6ab3
                int zip64 = 0;
kusano fc6ab3
kusano fc6ab3
                zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
kusano fc6ab3
                zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
kusano fc6ab3
                zi.dosDate = 0;
kusano fc6ab3
                zi.internal_fa = 0;
kusano fc6ab3
                zi.external_fa = 0;
kusano fc6ab3
                filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
kusano fc6ab3
kusano fc6ab3
/*
kusano fc6ab3
                err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
kusano fc6ab3
                                 NULL,0,NULL,0,NULL / * comment * /,
kusano fc6ab3
                                 (opt_compress_level != 0) ? Z_DEFLATED : 0,
kusano fc6ab3
                                 opt_compress_level);
kusano fc6ab3
*/
kusano fc6ab3
                if ((password != NULL) && (err==ZIP_OK))
kusano fc6ab3
                    err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
kusano fc6ab3
kusano fc6ab3
                zip64 = isLargeFile(filenameinzip);
kusano fc6ab3
kusano fc6ab3
                                                         /* The path name saved, should not include a leading slash. */
kusano fc6ab3
               /*if it did, windows/xp and dynazip couldn't read the zip file. */
kusano fc6ab3
                 savefilenameinzip = filenameinzip;
kusano fc6ab3
                 while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
kusano fc6ab3
                 {
kusano fc6ab3
                     savefilenameinzip++;
kusano fc6ab3
                 }
kusano fc6ab3
kusano fc6ab3
                 /*should the zip file contain any path at all?*/
kusano fc6ab3
                 if( opt_exclude_path )
kusano fc6ab3
                 {
kusano fc6ab3
                     const char *tmpptr;
kusano fc6ab3
                     const char *lastslash = 0;
kusano fc6ab3
                     for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
kusano fc6ab3
                     {
kusano fc6ab3
                         if( *tmpptr == '\\' || *tmpptr == '/')
kusano fc6ab3
                         {
kusano fc6ab3
                             lastslash = tmpptr;
kusano fc6ab3
                         }
kusano fc6ab3
                     }
kusano fc6ab3
                     if( lastslash != NULL )
kusano fc6ab3
                     {
kusano fc6ab3
                         savefilenameinzip = lastslash+1; // base filename follows last slash.
kusano fc6ab3
                     }
kusano fc6ab3
                 }
kusano fc6ab3
kusano fc6ab3
                 /**/
kusano fc6ab3
                err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
kusano fc6ab3
                                 NULL,0,NULL,0,NULL /* comment*/,
kusano fc6ab3
                                 (opt_compress_level != 0) ? Z_DEFLATED : 0,
kusano fc6ab3
                                 opt_compress_level,0,
kusano fc6ab3
                                 /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
kusano fc6ab3
                                 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
kusano fc6ab3
                                 password,crcFile, zip64);
kusano fc6ab3
kusano fc6ab3
                if (err != ZIP_OK)
kusano fc6ab3
                    printf("error in opening %s in zipfile\n",filenameinzip);
kusano fc6ab3
                else
kusano fc6ab3
                {
kusano fc6ab3
                    fin = FOPEN_FUNC(filenameinzip,"rb");
kusano fc6ab3
                    if (fin==NULL)
kusano fc6ab3
                    {
kusano fc6ab3
                        err=ZIP_ERRNO;
kusano fc6ab3
                        printf("error in opening %s for reading\n",filenameinzip);
kusano fc6ab3
                    }
kusano fc6ab3
                }
kusano fc6ab3
kusano fc6ab3
                if (err == ZIP_OK)
kusano fc6ab3
                    do
kusano fc6ab3
                    {
kusano fc6ab3
                        err = ZIP_OK;
kusano fc6ab3
                        size_read = (int)fread(buf,1,size_buf,fin);
kusano fc6ab3
                        if (size_read < size_buf)
kusano fc6ab3
                            if (feof(fin)==0)
kusano fc6ab3
                        {
kusano fc6ab3
                            printf("error in reading %s\n",filenameinzip);
kusano fc6ab3
                            err = ZIP_ERRNO;
kusano fc6ab3
                        }
kusano fc6ab3
kusano fc6ab3
                        if (size_read>0)
kusano fc6ab3
                        {
kusano fc6ab3
                            err = zipWriteInFileInZip (zf,buf,size_read);
kusano fc6ab3
                            if (err<0)
kusano fc6ab3
                            {
kusano fc6ab3
                                printf("error in writing %s in the zipfile\n",
kusano fc6ab3
                                                 filenameinzip);
kusano fc6ab3
                            }
kusano fc6ab3
kusano fc6ab3
                        }
kusano fc6ab3
                    } while ((err == ZIP_OK) && (size_read>0));
kusano fc6ab3
kusano fc6ab3
                if (fin)
kusano fc6ab3
                    fclose(fin);
kusano fc6ab3
kusano fc6ab3
                if (err<0)
kusano fc6ab3
                    err=ZIP_ERRNO;
kusano fc6ab3
                else
kusano fc6ab3
                {
kusano fc6ab3
                    err = zipCloseFileInZip(zf);
kusano fc6ab3
                    if (err!=ZIP_OK)
kusano fc6ab3
                        printf("error in closing %s in the zipfile\n",
kusano fc6ab3
                                    filenameinzip);
kusano fc6ab3
                }
kusano fc6ab3
            }
kusano fc6ab3
        }
kusano fc6ab3
        errclose = zipClose(zf,NULL);
kusano fc6ab3
        if (errclose != ZIP_OK)
kusano fc6ab3
            printf("error in closing %s\n",filename_try);
kusano fc6ab3
    }
kusano fc6ab3
    else
kusano fc6ab3
    {
kusano fc6ab3
       do_help();
kusano fc6ab3
    }
kusano fc6ab3
kusano fc6ab3
    free(buf);
kusano fc6ab3
    return 0;
kusano fc6ab3
}