     } case ;
 
 M: windows can-seek-handle? ( handle -- ? )
-    handle>> handle>file-size zero? not ;
+    handle>> handle>file-size >boolean ;
 
 M: windows handle-length ( handle -- n/f )
-    handle>> handle>file-size [ f ] when-zero ;
+    handle>> handle>file-size
+    dup { 0 f } member? [ drop f ] when ;
 
 : file-error? ( n -- eof? )
     zero? [

locals make math math.bitwise namespaces sequences
specialized-arrays system threads tr windows windows.errors
windows.handles windows.kernel32 windows.shell32 windows.time
windows.types ;
SPECIALIZED-ARRAY: ushort
IN: io.files.windows



ERROR: invalid-file-size n ;

: (handle>file-size) ( handle -- n )
    0 ulonglong <ref> [ GetFileSizeEx win32-error=0/f ] keep ulonglong deref ;

! Returns T{ windows-error f 1 "Incorrect function." } if stream is not seekable
: handle>file-size ( handle -- n/f )
    '[ _ (handle>file-size) ]
     [ dup n>> 1 = [ drop f ] [ rethrow ] if ] recover ;

ERROR: seek-before-start n ;

