]> gitweb.factorcode.org Git - factor.git/commitdiff
Check if streams are seekable in Windows
authorDoug Coleman <doug.coleman@gmail.com>
Wed, 19 Oct 2011 08:16:53 +0000 (01:16 -0700)
committerDoug Coleman <doug.coleman@gmail.com>
Wed, 19 Oct 2011 08:16:53 +0000 (01:16 -0700)
basis/io/files/windows/windows.factor

index 67e01833f63674d58d789205bdc47135cdfc5cb1..f25a19df9b3cc079e0dc746406600340343c36c0 100755 (executable)
@@ -9,7 +9,7 @@ io.streams.c io.streams.null io.timeouts kernel libc literals
 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 ;
+windows.types fry ;
 SPECIALIZED-ARRAY: ushort
 IN: io.files.windows
 
@@ -133,9 +133,14 @@ M: windows init-io ( -- )
 
 ERROR: invalid-file-size n ;
 
-: handle>file-size ( handle -- 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 ;
 
 : set-seek-ptr ( n handle -- )
@@ -152,10 +157,11 @@ M: windows seek-handle ( n seek-type handle -- )
     } 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? [