Skip to content

Commit b33d31c

Browse files
committed
Allow to move file pointer in append mode as well
1 parent c08837d commit b33d31c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

System/File/AbstractFilePath/Windows.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import System.AbstractFilePath.Windows ( WindowsFilePath )
88

99
import qualified System.Win32 as Win32
1010
import qualified System.Win32.WindowsString.File as WS
11+
import Control.Monad (when, void)
1112
#if defined(__IO_MANAGER_WINIO__)
1213
import GHC.IO.SubSystem
1314
#endif
@@ -31,12 +32,15 @@ openFile fp iomode = bracketOnError
3132
#endif
3233
Nothing)
3334
Win32.closeHandle
34-
Win32.hANDLEToHandle
35+
toHandle
3536
where
37+
toHandle h = do
38+
when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END
39+
Win32.hANDLEToHandle h
3640
accessMode = case iomode of
3741
ReadMode -> Win32.gENERIC_READ
3842
WriteMode -> Win32.gENERIC_WRITE
39-
AppendMode -> Win32.fILE_APPEND_DATA
43+
AppendMode -> Win32.gENERIC_WRITE .|. Win32.fILE_APPEND_DATA
4044
ReadWriteMode -> Win32.gENERIC_READ .|. Win32.gENERIC_WRITE
4145

4246
createMode = case iomode of

0 commit comments

Comments
 (0)