From owner-p4-projects@FreeBSD.ORG Fri Aug 8 16:09:10 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 28CF21065676; Fri, 8 Aug 2008 16:09:10 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DF92C1065683 for ; Fri, 8 Aug 2008 16:09:09 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id CD7E38FC19 for ; Fri, 8 Aug 2008 16:09:09 +0000 (UTC) (envelope-from strauss@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m78G99Fq085230 for ; Fri, 8 Aug 2008 16:09:09 GMT (envelope-from strauss@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m78G99dS085228 for perforce@freebsd.org; Fri, 8 Aug 2008 16:09:09 GMT (envelope-from strauss@FreeBSD.org) Date: Fri, 8 Aug 2008 16:09:09 GMT Message-Id: <200808081609.m78G99dS085228@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to strauss@FreeBSD.org using -f From: Anselm Strauss To: Perforce Change Reviews Cc: Subject: PERFORCE change 146916 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Aug 2008 16:09:10 -0000 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; +}