less aggressive open-file for file-times, use FILETIME struct now

db4
Doug Coleman 2009-08-25 17:34:06 -05:00
parent 3507616f3b
commit c50eaf1c29
4 changed files with 28 additions and 26 deletions

View File

@ -0,0 +1,6 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test io.files.info.windows system kernel ;
IN: io.files.info.windows.tests
[ ] [ vm file-times 3drop ] unit-test

View File

@ -188,10 +188,10 @@ M: winnt file-systems ( -- array )
: file-times ( path -- timestamp timestamp timestamp ) : file-times ( path -- timestamp timestamp timestamp )
[ [
normalize-path open-existing &dispose handle>> normalize-path open-read &dispose handle>>
"FILETIME" <c-object> FILETIME <struct>
"FILETIME" <c-object> FILETIME <struct>
"FILETIME" <c-object> FILETIME <struct>
[ GetFileTime win32-error=0/f ] 3keep [ GetFileTime win32-error=0/f ] 3keep
[ FILETIME>timestamp >local-time ] tri@ [ FILETIME>timestamp >local-time ] tri@
] with-destructors ; ] with-destructors ;

View File

@ -216,15 +216,15 @@ C-STRUCT: OVERLAPPED
{ "DWORD" "offset-high" } { "DWORD" "offset-high" }
{ "HANDLE" "event" } ; { "HANDLE" "event" } ;
C-STRUCT: SYSTEMTIME STRUCT: SYSTEMTIME
{ "WORD" "wYear" } { wYear WORD }
{ "WORD" "wMonth" } { wMonth WORD }
{ "WORD" "wDayOfWeek" } { wDayOfWeek WORD }
{ "WORD" "wDay" } { wDay WORD }
{ "WORD" "wHour" } { wHour WORD }
{ "WORD" "wMinute" } { wMinute WORD }
{ "WORD" "wSecond" } { wSecond WORD }
{ "WORD" "wMilliseconds" } ; { wMilliseconds WORD } ;
C-STRUCT: TIME_ZONE_INFORMATION C-STRUCT: TIME_ZONE_INFORMATION
{ "LONG" "Bias" } { "LONG" "Bias" }
@ -235,9 +235,9 @@ C-STRUCT: TIME_ZONE_INFORMATION
{ "SYSTEMTIME" "DaylightDate" } { "SYSTEMTIME" "DaylightDate" }
{ "LONG" "DaylightBias" } ; { "LONG" "DaylightBias" } ;
C-STRUCT: FILETIME STRUCT: FILETIME
{ "DWORD" "dwLowDateTime" } { dwLowDateTime DWORD }
{ "DWORD" "dwHighDateTime" } ; { dwHighDateTime DWORD } ;
C-STRUCT: STARTUPINFO C-STRUCT: STARTUPINFO
{ "DWORD" "cb" } { "DWORD" "cb" }

View File

@ -1,7 +1,8 @@
! Copyright (C) 2007 Doug Coleman. ! Copyright (C) 2007 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.c-types kernel math windows.errors USING: alien alien.c-types kernel math windows.errors
windows.kernel32 namespaces calendar math.bitwise ; windows.kernel32 namespaces calendar math.bitwise accessors
classes.struct ;
IN: windows.time IN: windows.time
: >64bit ( lo hi -- n ) : >64bit ( lo hi -- n )
@ -11,15 +12,13 @@ IN: windows.time
1601 1 1 0 0 0 instant <timestamp> ; 1601 1 1 0 0 0 instant <timestamp> ;
: FILETIME>windows-time ( FILETIME -- n ) : FILETIME>windows-time ( FILETIME -- n )
[ FILETIME-dwLowDateTime ] [ dwLowDateTime>> ] [ dwHighDateTime>> ] bi >64bit ;
[ FILETIME-dwHighDateTime ]
bi >64bit ;
: windows-time>timestamp ( n -- timestamp ) : windows-time>timestamp ( n -- timestamp )
10000000 /i seconds windows-1601 swap time+ ; 10000000 /i seconds windows-1601 swap time+ ;
: windows-time ( -- n ) : windows-time ( -- n )
"FILETIME" <c-object> [ GetSystemTimeAsFileTime ] keep FILETIME <struct> [ GetSystemTimeAsFileTime ] keep
FILETIME>windows-time ; FILETIME>windows-time ;
: timestamp>windows-time ( timestamp -- n ) : timestamp>windows-time ( timestamp -- n )
@ -27,11 +26,8 @@ IN: windows.time
>gmt windows-1601 (time-) 10000000 * >integer ; >gmt windows-1601 (time-) 10000000 * >integer ;
: windows-time>FILETIME ( n -- FILETIME ) : windows-time>FILETIME ( n -- FILETIME )
"FILETIME" <c-object> [ FILETIME <struct> ] dip
[ [ 32 bits >>dwLowDateTime ] [ -32 shift >>dwHighDateTime ] bi ;
[ [ 32 bits ] dip set-FILETIME-dwLowDateTime ]
[ [ -32 shift ] dip set-FILETIME-dwHighDateTime ] 2bi
] keep ;
: timestamp>FILETIME ( timestamp -- FILETIME/f ) : timestamp>FILETIME ( timestamp -- FILETIME/f )
dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ; dup [ >gmt timestamp>windows-time windows-time>FILETIME ] when ;