Date: Thu, 17 Jul 2008 15:56:11 GMT From: Anselm Strauss <strauss@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 145374 for review Message-ID: <200807171556.m6HFuBue082067@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=145374 Change 145374 by strauss@strauss_marvelman on 2008/07/17 15:55:37 Some work on the central directory stuff Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#9 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#9 (text+ko) ==== @@ -56,6 +56,25 @@ char extra_length[2]; }; +struct zip_file_header { + char signature[4]; + char version_by[2]; + char version_extract[2]; + char flags[2]; + char compression[2]; + char timedate[4]; + char crc32[4]; + char compressed_size[4]; + char uncompressed_size[4]; + char filename_length[2]; + char extra_length[2]; + char comment_length[2]; + char disk_number[2]; + char attributes_internal[2]; + char attributes_external[4]; + char offset[4]; +}; + struct zip_data_descriptor { char signature[4]; /* Not mandatory, but recommended by specification. */ char crc32[4]; @@ -63,15 +82,15 @@ char uncompressed_size[4]; }; -struct zip_file_header { - struct zip_file_header *next; +struct zip_entry_list { + struct zip_entry_list *next; struct archive_entry *entry; - uint64_t offset; + /* uint64_t offset; */ /* Whatfor? */ }; struct zip { struct zip_data_descriptor data_descriptor; - struct zip_file_header *central_directory; + struct zip_entry_list *central_directory; }; int @@ -80,7 +99,7 @@ struct archive_write *a = (struct archive_write *)_a; struct zip *zip; - /* If someone else was already registered, unregister them. */ + /* If another format was already registered, unregister it. */ if (a->format_destroy != NULL) (a->format_destroy)(a); @@ -90,6 +109,7 @@ return (ARCHIVE_FATAL); } memset(zip, 0, sizeof(*zip)); + zip->central_directory = NULL; /* To be sure. */ a->format_data = zip; a->pad_uncompressed = 0; /* Actually not needed for now, since no compression support yet. */ @@ -120,6 +140,7 @@ struct zip *zip; struct zip_local_file_header h; struct zip_data_descriptor *d; + struct zip_entry_list l; int ret; zip = (struct zip *) a->format_data; @@ -152,7 +173,12 @@ /* Not used. */ encode(0, &h.extra_length, sizeof(h.extra_length)); - /* TODO: Append entry to central directory. */ + /* Append archive entry to the central directory data. + * Storing in reverse order, for ease of coding. + * According to specification order should not matter, right? */ + l.entry = entry; + l.next = zip->central_directory; + zip->central_directory = &l; int64_t size = archive_entry_size(entry); encode(size, &d->compressed_size, sizeof(d->compressed_size)); @@ -188,12 +214,15 @@ archive_write_zip_finish_entry(struct archive_write *a) { /* Write the data descripter after file data has been written. */ + int ret; struct zip *zip = (struct zip *) a->format_data; struct zip_data_descriptor *d = (struct zip_data_descriptor *) &zip->data_descriptor; + ret = (a->compressor.write)(a, d, sizeof(d)); if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL); + return (ret); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807171556.m6HFuBue082067>