Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Aug 2008 16:09:09 GMT
From:      Anselm Strauss <strauss@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 146916 for review
Message-ID:  <200808081609.m78G99dS085228@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=146916

Change 146916 by strauss@strauss_marvelman on 2008/08/08 16:08:59

	Unix to DOS date/time conversion

Affected files ...

.. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#25 edit

Differences ...

==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#25 (text+ko) ====

@@ -50,6 +50,7 @@
 static int archive_write_zip_finish_entry(struct archive_write *);
 static int archive_write_zip_header(struct archive_write *, struct archive_entry *);
 static void zip_encode(uint64_t, void *, size_t);
+static unsigned int dos_time(const time_t);
 
 struct zip_local_file_header {
 	char signature[4];
@@ -196,14 +197,14 @@
 	 * The fields this is true for and the reason why are:
 	 * 
 	 *   - compression: Not yet supported (TODO)
-	 *   - timedate: Means standard input (TODO)
 	 *   - crc32, compressed_size, uncompressed_size: written in data descriptor
 	 *   - extra_length: not used (TODO)
 	 */
 	memset(&h, 0, sizeof(h));
 	zip_encode(ZIP_SIGNATURE_LOCAL_FILE_HEADER, &h.signature, sizeof(h.signature));
 	zip_encode(0x0200, &h.version, sizeof(h.version));
-	zip_encode(1 << 2, &h.flags, sizeof(h.flags)); /* Flagging bit 3 for using data descriptor. */
+	zip_encode(0x4, &h.flags, sizeof(h.flags)); /* Flagging bit 3 for using data descriptor. */
+	zip_encode(dos_time(archive_entry_mtime(entry)), &h.timedate, sizeof(h.timedate));
 	zip_encode(strlen(path), &h.filename_length, sizeof(h.filename_length));
 	
 	/* This will surely change when compression is implemented. */
@@ -301,11 +302,12 @@
 		/* Formatting individual header fields per entry. */
 		size = archive_entry_size(l->entry);
 		path = archive_entry_pathname(l->entry);
+		zip_encode(dos_time(archive_entry_mtime(l->entry)), &h.timedate, sizeof(h.timedate));
+		zip_encode(l->crc32, &h.crc32, sizeof(h.crc32));
 		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));
-		zip_encode(l->crc32, &h.crc32, sizeof(h.crc32));
 		
 		/* Writing file header. */
 		ret = (a->compressor.write)(a, &h, sizeof(h));
@@ -371,3 +373,27 @@
 		p++;
 	}
 }
+
+/* Convert into MSDOS-style date/time. */
+static unsigned int
+dos_time(const time_t unix_time)
+{
+	struct tm *time;
+	unsigned int dos_time;
+	
+	time = gmtime(&unix_time);
+	
+	dos_time = 0;
+	dos_time += ((time->tm_year - 80) & 0x7f) << 9;
+	dos_time += ((time->tm_mon + 1) & 0x0f) << 5;
+	dos_time += (time->tm_mday & 0x1f);
+	dos_time <<= 16;
+	dos_time += (time->tm_hour & 0x1f) << 11;
+	dos_time += (time->tm_min & 0x3f) << 5;
+	dos_time += (time->tm_sec & 0x3e) >> 1; /* Only counting every 2 seconds -> [0..30], right? */
+	
+	/* free(&dos_time); */
+	/* TODO: Getting error when freeing the struct, why? */
+	
+	return dos_time;
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808081609.m78G99dS085228>