PERFORCE change 145424 for review
Anselm Strauss
strauss at FreeBSD.org
Fri Jul 18 13:20:27 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=145424
Change 145424 by strauss at strauss_marvelman on 2008/07/18 13:19:28
added writing of offsets in central directory file headers
Affected files ...
.. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#13 edit
Differences ...
==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#13 (text+ko) ====
@@ -86,7 +86,7 @@
struct zip_file_header_link {
struct zip_file_header_link *next;
struct archive_entry *entry;
- /* uint64_t offset; */ /* Whatfor? */
+ off_t offset;
};
struct zip {
@@ -148,6 +148,23 @@
d = (struct zip_data_descriptor *) &zip->data_descriptor;
path = archive_entry_pathname(entry);
+ /* 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 = (struct zip_file_header_link *) malloc(sizeof(*l));
+ if (l == NULL) {
+ archive_set_error(&a->archive, ENOMEM, "Can't allocate zip header data");
+ return (ARCHIVE_FATAL);
+ }
+ l->entry = entry;
+ l->next = zip->central_directory;
+ zip->central_directory = l;
+
+ /* Store the offset of this header for later use in central directory.
+ * TODO: Offset actually are 8 bytes, for big archives this won't fit into
+ * the 4 bytes field. Either use ZIP64, or return error. */
+ l->offset = a->archive.raw_position;
+
/*
* Formatting local file header.
* Some fields are not explicitely set after they were set to 0
@@ -176,19 +193,6 @@
ret = (a->compressor.write)(a, path, strlen(path));
if (ret != ARCHIVE_OK) return (ARCHIVE_FATAL);
-
- /* 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 = (struct zip_file_header_link *) malloc(sizeof(*l));
- if (l == NULL) {
- archive_set_error(&a->archive, ENOMEM, "Can't allocate zip header data");
- return (ARCHIVE_FATAL);
- }
- l->entry = entry;
- l->next = zip->central_directory;
- zip->central_directory = l;
-
return (ARCHIVE_OK);
}
@@ -256,6 +260,7 @@
zip_encode(size, &h.compressed_size, sizeof(h.compressed_size));
zip_encode(size, &h.uncompressed_size, sizeof(h.uncompressed_size));
zip_encode(strlen(path), &h.filename_length, sizeof(h.filename_length));
+ zip_encode(l->offset, &h.offset, sizeof(h.offset));
/* Writing file header. */
ret = (a->compressor.write)(a, &h, sizeof(h));
More information about the p4-projects
mailing list