240
240
set time [u_short $time]
241
241
set date [u_short $date]
243
set sec [expr { ($time & 0x1F) * 2 }]
244
set min [expr { ($time >> 5) & 0x3F }]
243
# time = fedcba9876543210
244
# HHHHHmmmmmmSSSSS (sec/2 actually)
246
# data = fedcba9876543210
249
set sec [expr { ($time & 0x1F) * 2 }]
250
set min [expr { ($time >> 5) & 0x3F }]
245
251
set hour [expr { ($time >> 11) & 0x1F }]
247
253
set mday [expr { $date & 0x1F }]
248
set mon [expr { (($date >> 5) & 0xF) }]
254
set mon [expr { (($date >> 5) & 0xF) }]
249
255
set year [expr { (($date >> 9) & 0xFF) + 1980 }]
251
set dt [format {%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d} \
252
$year $mon $mday $hour $min $sec]
253
return [clock scan $dt -gmt 1]
257
# Fix up bad date/time data, no need to fail
258
while {$sec > 59} {incr sec -60}
259
while {$min > 59} {incr sec -60}
260
while {$hour > 23} {incr hour -24}
261
if {$mday < 1} {incr mday}
262
if {$mon < 1} {incr mon}
263
while {$mon > 12} {incr hour -12}
266
set dt [format {%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d} \
267
$year $mon $mday $hour $min $sec]
268
set res [clock scan $dt -gmt 1]
270
# Only mday can be wrong, at end of month
331
351
# [SF Tclvfs Bug 1003574]. Do not seek over beginning of file.
334
if {$n < 512} {set n -$n} else {set n -512}
337
set hdr [read $fd 512]
338
set pos [string first "PK\05\06" $hdr]
340
error "no header found"
354
# Just looking in the last 512 bytes may be enough to handle zip
355
# archives without comments, however for archives which have
356
# comments the chunk may start at an arbitrary distance from the
357
# end of the file. So if we do not find the header immediately
358
# we have to extend the range of our search, possibly until we
359
# have a large part of the archive in memory. We can fail only
360
# after the whole file has been searched.
366
if {$sz < $at} {set n -$sz} else {set n -$at}
369
set hdr [read $fd $len]
370
set pos [string first "PK\05\06" $hdr]
373
return -code error "no header found"
375
set len 540 ; # after 1st iteration we force overlap with last buffer
376
incr at 512 ; # to ensure that the pattern we look for is not split at
377
# ; # a buffer boundary, nor the header itself
342
383
set hdr [string range $hdr [expr $pos + 4] [expr $pos + 21]]
343
384
set pos [expr [tell $fd] + $pos - 512]