Sync libsvn_diff from subversion r876937
[TortoiseGit.git] / src / TortoiseMerge / libsvn_diff / zip.c
blob135d0974f0eaa52929af3689778ddaccc883ae66
1 /* zip.c -- IO on .zip files using zlib
2 Version 0.15 beta, Mar 19th, 1998,
4 Read zip.h for more info
5 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "zlib.h"
12 #include "zip.h"
13 #include "zutil.h"
15 #ifdef STDC
16 # include <stddef.h>
17 # include <string.h>
18 # include <stdlib.h>
19 #endif
20 #ifdef NO_ERRNO_H
21 extern int errno;
22 #else
23 # include <errno.h>
24 #endif
27 #ifndef local
28 # define local static
29 #endif
30 /* compile with -Dlocal if your debugger can't find static symbols */
32 #ifndef VERSIONMADEBY
33 # define VERSIONMADEBY (0x0) /* platform depedent */
34 #endif
36 #ifndef Z_BUFSIZE
37 #define Z_BUFSIZE (16384)
38 #endif
40 #ifndef Z_MAXFILENAMEINZIP
41 #define Z_MAXFILENAMEINZIP (256)
42 #endif
44 #ifndef ALLOC
45 # define ALLOC(size) (malloc(size))
46 #endif
47 #ifndef TRYFREE
48 # define TRYFREE(p) {if (p) free(p);}
49 #endif
52 #define SIZECENTRALDIRITEM (0x2e)
53 #define SIZEZIPLOCALHEADER (0x1e)
56 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
58 #ifndef SEEK_CUR
59 #define SEEK_CUR 1
60 #endif
62 #ifndef SEEK_END
63 #define SEEK_END 2
64 #endif
66 #ifndef SEEK_SET
67 #define SEEK_SET 0
68 #endif
70 const char zip_copyright[] =
71 " zip 0.15 Copyright 1998 Gilles Vollant ";
74 #define SIZEDATA_INDATABLOCK (4096-(4*4))
76 #define LOCALHEADERMAGIC (0x04034b50)
77 #define CENTRALHEADERMAGIC (0x02014b50)
78 #define ENDHEADERMAGIC (0x06054b50)
80 #define FLAG_LOCALHEADER_OFFSET (0x06)
81 #define CRC_LOCALHEADER_OFFSET (0x0e)
83 #define SIZECENTRALHEADER (0x2e) /* 46 */
85 typedef struct linkedlist_datablock_internal_s
87 struct linkedlist_datablock_internal_s* next_datablock;
88 uLong avail_in_this_block;
89 uLong filled_in_this_block;
90 uLong unused; /* for future use and alignement */
91 unsigned char data[SIZEDATA_INDATABLOCK];
92 } linkedlist_datablock_internal;
94 typedef struct linkedlist_data_s
96 linkedlist_datablock_internal* first_block;
97 linkedlist_datablock_internal* last_block;
98 } linkedlist_data;
101 typedef struct
103 z_stream stream; /* zLib stream structure for inflate */
104 int stream_initialised; /* 1 is stream is initialised */
105 uInt pos_in_buffered_data; /* last written byte in buffered_data */
107 uLong pos_local_header; /* offset of the local header of the file
108 currenty writing */
109 char* central_header; /* central header data for the current file */
110 uLong size_centralheader; /* size of the central header for cur file */
111 uLong flag; /* flag of the file currently writing */
113 int method; /* compression method of file currenty wr.*/
114 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
115 uLong dosDate;
116 uLong crc32;
117 } curfile_info;
119 typedef struct
121 FILE * filezip;
122 linkedlist_data central_dir;/* datablock with central dir in construction*/
123 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
124 curfile_info ci; /* info on the file curretly writing */
126 uLong begin_pos; /* position of the beginning of the zipfile */
127 uLong number_entry;
128 } zip_internal;
130 local linkedlist_datablock_internal* allocate_new_datablock()
132 linkedlist_datablock_internal* ldi;
133 ldi = (linkedlist_datablock_internal*)
134 ALLOC(sizeof(linkedlist_datablock_internal));
135 if (ldi!=NULL)
137 ldi->next_datablock = NULL ;
138 ldi->filled_in_this_block = 0 ;
139 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
141 return ldi;
144 local void free_datablock(ldi)
145 linkedlist_datablock_internal* ldi;
147 while (ldi!=NULL)
149 linkedlist_datablock_internal* ldinext = ldi->next_datablock;
150 TRYFREE(ldi);
151 ldi = ldinext;
155 local void init_linkedlist(ll)
156 linkedlist_data* ll;
158 ll->first_block = ll->last_block = NULL;
161 local void free_linkedlist(ll)
162 linkedlist_data* ll;
164 free_datablock(ll->first_block);
165 ll->first_block = ll->last_block = NULL;
169 local int add_data_in_datablock(ll,buf,len)
170 linkedlist_data* ll;
171 const void* buf;
172 uLong len;
174 linkedlist_datablock_internal* ldi;
175 const unsigned char* from_copy;
177 if (ll==NULL)
178 return ZIP_INTERNALERROR;
180 if (ll->last_block == NULL)
182 ll->first_block = ll->last_block = allocate_new_datablock();
183 if (ll->first_block == NULL)
184 return ZIP_INTERNALERROR;
187 ldi = ll->last_block;
188 from_copy = (unsigned char*)buf;
190 while (len>0)
192 uInt copy_this;
193 uInt i;
194 unsigned char* to_copy;
196 if (ldi->avail_in_this_block==0)
198 ldi->next_datablock = allocate_new_datablock();
199 if (ldi->next_datablock == NULL)
200 return ZIP_INTERNALERROR;
201 ldi = ldi->next_datablock ;
202 ll->last_block = ldi;
205 if (ldi->avail_in_this_block < len)
206 copy_this = (uInt)ldi->avail_in_this_block;
207 else
208 copy_this = (uInt)len;
210 to_copy = &(ldi->data[ldi->filled_in_this_block]);
212 for (i=0;i<copy_this;i++)
213 *(to_copy+i)=*(from_copy+i);
215 ldi->filled_in_this_block += copy_this;
216 ldi->avail_in_this_block -= copy_this;
217 from_copy += copy_this ;
218 len -= copy_this;
220 return ZIP_OK;
224 local int write_datablock(fout,ll)
225 FILE * fout;
226 linkedlist_data* ll;
228 linkedlist_datablock_internal* ldi;
229 ldi = ll->first_block;
230 while (ldi!=NULL)
232 if (ldi->filled_in_this_block > 0)
233 if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,1,fout)!=1)
234 return ZIP_ERRNO;
235 ldi = ldi->next_datablock;
237 return ZIP_OK;
240 /****************************************************************************/
242 /* ===========================================================================
243 Outputs a long in LSB order to the given file
244 nbByte == 1, 2 or 4 (byte, short or long)
247 local int ziplocal_putValue OF((FILE *file, uLong x, int nbByte));
248 local int ziplocal_putValue (file, x, nbByte)
249 FILE *file;
250 uLong x;
251 int nbByte;
253 unsigned char buf[4];
254 int n;
255 for (n = 0; n < nbByte; n++) {
256 buf[n] = (unsigned char)(x & 0xff);
257 x >>= 8;
259 if (fwrite(buf,nbByte,1,file)!=1)
260 return ZIP_ERRNO;
261 else
262 return ZIP_OK;
265 local void ziplocal_putValue_inmemory OF((void* dest, uLong x, int nbByte));
266 local void ziplocal_putValue_inmemory (dest, x, nbByte)
267 void* dest;
268 uLong x;
269 int nbByte;
271 unsigned char* buf=(unsigned char*)dest;
272 int n;
273 for (n = 0; n < nbByte; n++) {
274 buf[n] = (unsigned char)(x & 0xff);
275 x >>= 8;
278 /****************************************************************************/
281 local uLong ziplocal_TmzDateToDosDate(ptm,dosDate)
282 tm_zip* ptm;
283 uLong dosDate;
285 uLong year = (uLong)ptm->tm_year;
286 if (year>1980)
287 year-=1980;
288 else if (year>80)
289 year-=80;
290 return
291 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
292 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
296 /****************************************************************************/
298 extern zipFile ZEXPORT zipOpen (pathname, append)
299 const char *pathname;
300 int append;
302 zip_internal ziinit;
303 zip_internal* zi;
305 ziinit.filezip = fopen(pathname,(append == 0) ? "wb" : "ab");
306 if (ziinit.filezip == NULL)
307 return NULL;
308 ziinit.begin_pos = ftell(ziinit.filezip);
309 ziinit.in_opened_file_inzip = 0;
310 ziinit.ci.stream_initialised = 0;
311 ziinit.number_entry = 0;
312 init_linkedlist(&(ziinit.central_dir));
315 zi = (zip_internal*)ALLOC(sizeof(zip_internal));
316 if (zi==NULL)
318 fclose(ziinit.filezip);
319 return NULL;
322 *zi = ziinit;
323 return (zipFile)zi;
326 extern int ZEXPORT zipOpenNewFileInZip (file, filename, zipfi,
327 extrafield_local, size_extrafield_local,
328 extrafield_global, size_extrafield_global,
329 comment, method, level)
330 zipFile file;
331 const char* filename;
332 const zip_fileinfo* zipfi;
333 const void* extrafield_local;
334 uInt size_extrafield_local;
335 const void* extrafield_global;
336 uInt size_extrafield_global;
337 const char* comment;
338 int method;
339 int level;
341 zip_internal* zi;
342 uInt size_filename;
343 uInt size_comment;
344 uInt i;
345 int err = ZIP_OK;
347 if (file == NULL)
348 return ZIP_PARAMERROR;
349 if ((method!=0) && (method!=Z_DEFLATED))
350 return ZIP_PARAMERROR;
352 zi = (zip_internal*)file;
354 if (zi->in_opened_file_inzip == 1)
356 err = zipCloseFileInZip (file);
357 if (err != ZIP_OK)
358 return err;
362 if (filename==NULL)
363 filename="-";
365 if (comment==NULL)
366 size_comment = 0;
367 else
368 size_comment = strlen(comment);
370 size_filename = strlen(filename);
372 if (zipfi == NULL)
373 zi->ci.dosDate = 0;
374 else
376 if (zipfi->dosDate != 0)
377 zi->ci.dosDate = zipfi->dosDate;
378 else zi->ci.dosDate = ziplocal_TmzDateToDosDate(&zipfi->tmz_date,zipfi->dosDate);
381 zi->ci.flag = 0;
382 if ((level==8) || (level==9))
383 zi->ci.flag |= 2;
384 if ((level==2))
385 zi->ci.flag |= 4;
386 if ((level==1))
387 zi->ci.flag |= 6;
389 zi->ci.crc32 = 0;
390 zi->ci.method = method;
391 zi->ci.stream_initialised = 0;
392 zi->ci.pos_in_buffered_data = 0;
393 zi->ci.pos_local_header = ftell(zi->filezip);
394 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename +
395 size_extrafield_global + size_comment;
396 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader);
398 ziplocal_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
399 /* version info */
400 ziplocal_putValue_inmemory(zi->ci.central_header+4,(uLong)VERSIONMADEBY,2);
401 ziplocal_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
402 ziplocal_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
403 ziplocal_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
404 ziplocal_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
405 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
406 ziplocal_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
407 ziplocal_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
408 ziplocal_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
409 ziplocal_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
410 ziplocal_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
411 ziplocal_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
413 if (zipfi==NULL)
414 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
415 else
416 ziplocal_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
418 if (zipfi==NULL)
419 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
420 else
421 ziplocal_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
423 ziplocal_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header,4);
425 for (i=0;i<size_filename;i++)
426 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
428 for (i=0;i<size_extrafield_global;i++)
429 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
430 *(((const char*)extrafield_global)+i);
432 for (i=0;i<size_comment;i++)
433 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
434 size_extrafield_global+i) = *(filename+i);
435 if (zi->ci.central_header == NULL)
436 return ZIP_INTERNALERROR;
438 /* write the local header */
439 err = ziplocal_putValue(zi->filezip,(uLong)LOCALHEADERMAGIC,4);
441 if (err==ZIP_OK)
442 err = ziplocal_putValue(zi->filezip,(uLong)20,2);/* version needed to extract */
443 if (err==ZIP_OK)
444 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.flag,2);
446 if (err==ZIP_OK)
447 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.method,2);
449 if (err==ZIP_OK)
450 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.dosDate,4);
452 if (err==ZIP_OK)
453 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* crc 32, unknown */
454 if (err==ZIP_OK)
455 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* compressed size, unknown */
456 if (err==ZIP_OK)
457 err = ziplocal_putValue(zi->filezip,(uLong)0,4); /* uncompressed size, unknown */
459 if (err==ZIP_OK)
460 err = ziplocal_putValue(zi->filezip,(uLong)size_filename,2);
462 if (err==ZIP_OK)
463 err = ziplocal_putValue(zi->filezip,(uLong)size_extrafield_local,2);
465 if ((err==ZIP_OK) && (size_filename>0))
466 if (fwrite(filename,(uInt)size_filename,1,zi->filezip)!=1)
467 err = ZIP_ERRNO;
469 if ((err==ZIP_OK) && (size_extrafield_local>0))
470 if (fwrite(extrafield_local,(uInt)size_extrafield_local,1,zi->filezip)
471 !=1)
472 err = ZIP_ERRNO;
474 zi->ci.stream.avail_in = (uInt)0;
475 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
476 zi->ci.stream.next_out = zi->ci.buffered_data;
477 zi->ci.stream.total_in = 0;
478 zi->ci.stream.total_out = 0;
480 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED))
482 zi->ci.stream.zalloc = (alloc_func)0;
483 zi->ci.stream.zfree = (free_func)0;
484 zi->ci.stream.opaque = (voidpf)0;
486 err = deflateInit2(&zi->ci.stream, level,
487 Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, 0);
489 if (err==Z_OK)
490 zi->ci.stream_initialised = 1;
494 if (err==Z_OK)
495 zi->in_opened_file_inzip = 1;
496 return err;
499 extern int ZEXPORT zipWriteInFileInZip (file, buf, len)
500 zipFile file;
501 const voidp buf;
502 unsigned len;
504 zip_internal* zi;
505 int err=ZIP_OK;
507 if (file == NULL)
508 return ZIP_PARAMERROR;
509 zi = (zip_internal*)file;
511 if (zi->in_opened_file_inzip == 0)
512 return ZIP_PARAMERROR;
514 zi->ci.stream.next_in = buf;
515 zi->ci.stream.avail_in = len;
516 zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
518 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
520 if (zi->ci.stream.avail_out == 0)
522 if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
523 !=1)
524 err = ZIP_ERRNO;
525 zi->ci.pos_in_buffered_data = 0;
526 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
527 zi->ci.stream.next_out = zi->ci.buffered_data;
530 if (zi->ci.method == Z_DEFLATED)
532 uLong uTotalOutBefore = zi->ci.stream.total_out;
533 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
534 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
537 else
539 uInt copy_this,i;
540 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
541 copy_this = zi->ci.stream.avail_in;
542 else
543 copy_this = zi->ci.stream.avail_out;
544 for (i=0;i<copy_this;i++)
545 *(((char*)zi->ci.stream.next_out)+i) =
546 *(((const char*)zi->ci.stream.next_in)+i);
548 zi->ci.stream.avail_in -= copy_this;
549 zi->ci.stream.avail_out-= copy_this;
550 zi->ci.stream.next_in+= copy_this;
551 zi->ci.stream.next_out+= copy_this;
552 zi->ci.stream.total_in+= copy_this;
553 zi->ci.stream.total_out+= copy_this;
554 zi->ci.pos_in_buffered_data += copy_this;
559 return 0;
562 extern int ZEXPORT zipCloseFileInZip (file)
563 zipFile file;
565 zip_internal* zi;
566 int err=ZIP_OK;
568 if (file == NULL)
569 return ZIP_PARAMERROR;
570 zi = (zip_internal*)file;
572 if (zi->in_opened_file_inzip == 0)
573 return ZIP_PARAMERROR;
574 zi->ci.stream.avail_in = 0;
576 if (zi->ci.method == Z_DEFLATED)
577 while (err==ZIP_OK)
579 uLong uTotalOutBefore;
580 if (zi->ci.stream.avail_out == 0)
582 if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
583 !=1)
584 err = ZIP_ERRNO;
585 zi->ci.pos_in_buffered_data = 0;
586 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
587 zi->ci.stream.next_out = zi->ci.buffered_data;
589 uTotalOutBefore = zi->ci.stream.total_out;
590 err=deflate(&zi->ci.stream, Z_FINISH);
591 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
594 if (err==Z_STREAM_END)
595 err=ZIP_OK; /* this is normal */
597 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
598 if (fwrite(zi->ci.buffered_data,(uInt)zi->ci.pos_in_buffered_data,1,zi->filezip)
599 !=1)
600 err = ZIP_ERRNO;
602 if ((zi->ci.method == Z_DEFLATED) && (err==ZIP_OK))
604 err=deflateEnd(&zi->ci.stream);
605 zi->ci.stream_initialised = 0;
608 ziplocal_putValue_inmemory(zi->ci.central_header+16,(uLong)zi->ci.crc32,4); /*crc*/
609 ziplocal_putValue_inmemory(zi->ci.central_header+20,
610 (uLong)zi->ci.stream.total_out,4); /*compr size*/
611 ziplocal_putValue_inmemory(zi->ci.central_header+24,
612 (uLong)zi->ci.stream.total_in,4); /*uncompr size*/
614 if (err==ZIP_OK)
615 err = add_data_in_datablock(&zi->central_dir,zi->ci.central_header,
616 (uLong)zi->ci.size_centralheader);
617 free(zi->ci.central_header);
619 if (err==ZIP_OK)
621 long cur_pos_inzip = ftell(zi->filezip);
622 if (fseek(zi->filezip,
623 zi->ci.pos_local_header + 14,SEEK_SET)!=0)
624 err = ZIP_ERRNO;
626 if (err==ZIP_OK)
627 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.crc32,4); /* crc 32, unknown */
629 if (err==ZIP_OK) /* compressed size, unknown */
630 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_out,4);
632 if (err==ZIP_OK) /* uncompressed size, unknown */
633 err = ziplocal_putValue(zi->filezip,(uLong)zi->ci.stream.total_in,4);
635 if (fseek(zi->filezip,
636 cur_pos_inzip,SEEK_SET)!=0)
637 err = ZIP_ERRNO;
640 zi->number_entry ++;
641 zi->in_opened_file_inzip = 0;
643 return err;
646 extern int ZEXPORT zipClose (file, global_comment)
647 zipFile file;
648 const char* global_comment;
650 zip_internal* zi;
651 int err = 0;
652 uLong size_centraldir = 0;
653 uLong centraldir_pos_inzip ;
654 uInt size_global_comment;
655 if (file == NULL)
656 return ZIP_PARAMERROR;
657 zi = (zip_internal*)file;
659 if (zi->in_opened_file_inzip == 1)
661 err = zipCloseFileInZip (file);
664 if (global_comment==NULL)
665 size_global_comment = 0;
666 else
667 size_global_comment = strlen(global_comment);
670 centraldir_pos_inzip = ftell(zi->filezip);
671 if (err==ZIP_OK)
673 linkedlist_datablock_internal* ldi = zi->central_dir.first_block ;
674 while (ldi!=NULL)
676 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
677 if (fwrite(ldi->data,(uInt)ldi->filled_in_this_block,
678 1,zi->filezip) !=1 )
679 err = ZIP_ERRNO;
681 size_centraldir += ldi->filled_in_this_block;
682 ldi = ldi->next_datablock;
685 free_datablock(zi->central_dir.first_block);
687 if (err==ZIP_OK) /* Magic End */
688 err = ziplocal_putValue(zi->filezip,(uLong)ENDHEADERMAGIC,4);
690 if (err==ZIP_OK) /* number of this disk */
691 err = ziplocal_putValue(zi->filezip,(uLong)0,2);
693 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
694 err = ziplocal_putValue(zi->filezip,(uLong)0,2);
696 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
697 err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2);
699 if (err==ZIP_OK) /* total number of entries in the central dir */
700 err = ziplocal_putValue(zi->filezip,(uLong)zi->number_entry,2);
702 if (err==ZIP_OK) /* size of the central directory */
703 err = ziplocal_putValue(zi->filezip,(uLong)size_centraldir,4);
705 if (err==ZIP_OK) /* offset of start of central directory with respect to the
706 starting disk number */
707 err = ziplocal_putValue(zi->filezip,(uLong)centraldir_pos_inzip ,4);
709 if (err==ZIP_OK) /* zipfile comment length */
710 err = ziplocal_putValue(zi->filezip,(uLong)size_global_comment,2);
712 if ((err==ZIP_OK) && (size_global_comment>0))
713 if (fwrite(global_comment,(uInt)size_global_comment,1,zi->filezip) !=1 )
714 err = ZIP_ERRNO;
715 fclose(zi->filezip);
716 TRYFREE(zi);
718 return err;