11 # include <sys/types.h>
12 # include <sys/stat.h>
21 #define WRITEBUFFERSIZE (16384)
22 #define MAXFILENAME (256)
25 uLong
filetime(f
, tmzip
, dt
)
26 char *f
; /* name of file to get info on */
27 tm_zip
*tmzip
; /* return value: access, modific. and creation times */
28 uLong
*dt
; /* dostime */
36 hFind
= FindFirstFile(f
,&ff32
);
37 if (hFind
!= INVALID_HANDLE_VALUE
)
39 FileTimeToLocalFileTime(&(ff32
.ftLastWriteTime
),&ftLocal
);
40 FileTimeToDosDateTime(&ftLocal
,((LPWORD
)dt
)+1,((LPWORD
)dt
)+0);
49 uLong
filetime(f
, tmzip
, dt
)
50 char *f
; /* name of file to get info on */
51 tm_zip
*tmzip
; /* return value: access, modific. and creation times */
52 uLong
*dt
; /* dostime */
55 struct stat s
; /* results of stat() */
61 char name
[MAXFILENAME
];
64 if (name
[len
- 1] == '/')
66 /* not all systems allow stat'ing a file with / appended */
73 filedate
= localtime(&tm_t
);
75 tmzip
->tm_sec
= filedate
->tm_sec
;
76 tmzip
->tm_min
= filedate
->tm_min
;
77 tmzip
->tm_hour
= filedate
->tm_hour
;
78 tmzip
->tm_mday
= filedate
->tm_mday
;
79 tmzip
->tm_mon
= filedate
->tm_mon
;
80 tmzip
->tm_year
= filedate
->tm_year
;
85 uLong
filetime(f
, tmzip
, dt
)
86 char *f
; /* name of file to get info on */
87 tm_zip
*tmzip
; /* return value: access, modific. and creation times */
88 uLong
*dt
; /* dostime */
98 int check_exist_file(filename
)
103 ftestexist
= fopen(filename
,"rb");
104 if (ftestexist
==NULL
)
113 printf("MiniZip 0.15, demo of zLib + Zip package written by Gilles Vollant\n");
114 printf("more info at http://wwww.winimage/zLibDll/unzip.htm\n\n");
119 printf("Usage : minizip [-o] file.zip [files_to_add]\n\n") ;
128 int opt_compress_level
=Z_DEFAULT_COMPRESSION
;
129 int zipfilenamearg
= 0;
130 char filename_try
[MAXFILENAME
];
150 const char *p
=argv
[i
]+1;
155 if ((c
=='o') || (c
=='O'))
157 if ((c
>='0') && (c
<='9'))
158 opt_compress_level
= c
-'0';
162 if (zipfilenamearg
== 0)
167 size_buf
= WRITEBUFFERSIZE
;
168 buf
= (void*)malloc(size_buf
);
171 printf("Error allocating memory\n");
172 return ZIP_INTERNALERROR
;
175 if (zipfilenamearg
==0)
183 strcpy(filename_try
,argv
[zipfilenamearg
]);
184 len
=strlen(filename_try
);
186 if (filename_try
[i
]=='.')
190 strcat(filename_try
,".zip");
192 if (opt_overwrite
==0)
193 if (check_exist_file(filename_try
)!=0)
199 printf("The file %s exist. Overwrite ? [y]es, [n]o : ",filename_try
);
202 if ((rep
>='a') && (rep
<='z'))
205 while ((rep
!='Y') && (rep
!='N'));
215 zf
= zipOpen(filename_try
,0);
218 printf("error opening %s\n",filename_try
);
222 printf("creating %s\n",filename_try
);
224 for (i
=zipfilenamearg
+1;(i
<argc
) && (err
==ZIP_OK
);i
++)
226 if (((*(argv
[i
]))!='-') && ((*(argv
[i
]))!='/'))
230 const char* filenameinzip
= argv
[i
];
233 zi
.tmz_date
.tm_sec
= zi
.tmz_date
.tm_min
= zi
.tmz_date
.tm_hour
=
234 zi
.tmz_date
.tm_mday
= zi
.tmz_date
.tm_min
= zi
.tmz_date
.tm_year
= 0;
238 filetime(filenameinzip
,&zi
.tmz_date
,&zi
.dosDate
);
241 err
= zipOpenNewFileInZip(zf
,filenameinzip
,&zi
,
242 NULL
,0,NULL
,0,NULL
/* comment*/,
243 (opt_compress_level
!= 0) ? Z_DEFLATED
: 0,
247 printf("error in opening %s in zipfile\n",filenameinzip
);
250 fin
= fopen(filenameinzip
,"rb");
254 printf("error in opening %s for reading\n",filenameinzip
);
262 size_read
= fread(buf
,1,size_buf
,fin
);
263 if (size_read
< size_buf
)
266 printf("error in reading %s\n",filenameinzip
);
272 err
= zipWriteInFileInZip (zf
,buf
,size_read
);
275 printf("error in writing %s in the zipfile\n",
280 } while ((err
== ZIP_OK
) && (size_read
>0));
287 err
= zipCloseFileInZip(zf
);
289 printf("error in closing %s in the zipfile\n",
294 errclose
= zipClose(zf
,NULL
);
295 if (errclose
!= ZIP_OK
)
296 printf("error in closing %s\n",filename_try
);
301 return 0; /* to avoid warning */