Date: Sun, 10 Aug 2008 11:11:36 GMT From: Anselm Strauss <strauss@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 147070 for review Message-ID: <200808101111.m7ABBaQf081935@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147070 Change 147070 by strauss@strauss_marvelman on 2008/08/10 11:10:45 Unix to DOS time conversion test. Affected files ... .. //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#27 edit .. //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#7 edit Differences ... ==== //depot/projects/soc2008/strauss_libarchive/libarchive/archive_write_set_format_zip.c#27 (text+ko) ==== @@ -381,7 +381,9 @@ struct tm *time; unsigned int dos_time; - time = gmtime(&unix_time); + /* This will not preserve time when creating/extracting the archive + * on two systems with different time zones. */ + time = localtime(&unix_time); dos_time = 0; dos_time += ((time->tm_year - 80) & 0x7f) << 9; @@ -390,10 +392,7 @@ 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(time); */ - /* TODO: Getting error when freeing the struct, why? */ + dos_time += (time->tm_sec & 0x3e) >> 1; /* Only counting every 2 seconds. */ return dos_time; } ==== //depot/projects/soc2008/strauss_libarchive/libarchive/test/test_write_format_zip_no_compression.c#7 (text+ko) ==== @@ -18,6 +18,8 @@ const char *p, *q, *buffend; size_t used; int crc; + const time_t t = time(NULL); + struct tm *tm = localtime(&t); /* Create new ZIP archive in memory without padding. */ assert((a = archive_write_new()) != NULL); @@ -39,6 +41,7 @@ archive_entry_set_dev(entry, 12); archive_entry_set_ino(entry, 89); archive_entry_set_nlink(entry, 1); + archive_entry_set_mtime(entry, t, 0); assertEqualIntA(a, 0, archive_write_header(a, entry)); assertEqualIntA(a, sizeof(data1), archive_write_data(a, data1, sizeof(data1))); assertEqualIntA(a, sizeof(data2), archive_write_data(a, data2, sizeof(data2))); @@ -81,8 +84,8 @@ /* assertEqualInt(i2(p + 6), XXXX); */ /* Version needed to extract */ /* assertEqualInt(i2(p + 8), XXXX); */ /* Flags */ /* assertEqualInt(i2(p + 10), XXXX); */ /* Compression method */ - /* assertEqualInt(i2(p + 12), XXXX); */ /* File time */ - /* assertEqualInt(i2(p + 14), XXXX); */ /* File date */ + assertEqualInt(i2(p + 12), (tm->tm_hour * 2048) + (tm->tm_min * 32) + (tm->tm_sec / 2)); /* File time */ + assertEqualInt(i2(p + 14), ((tm->tm_year - 80) * 512) + ((tm->tm_mon + 1) * 32) + tm->tm_mday); /* File date */ crc = crc32(0, &data1, sizeof(data1)); crc = crc32(crc, &data2, sizeof(data2)); assertEqualInt(i4(p + 16), crc); /* CRC-32 */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808101111.m7ABBaQf081935>