on master help sign in
Make binary files the default when opening.

The reason is that most things on windows handles unix line endings just fine and this leads to terrible bugs when writing binary files. fopen still allows opening of files without the "b". This only has effect on Windows, but POSIX systems allows the "b" as a noop.

commit56c20587e868eb4f5dd3e04ac920d9f0b7f8d6ca authorNiklas Larsson <niklas@mm.st> dateSat 9 Mar 2019, 15:58 (8 years ago) parent609f712
3 files changed+12−7
CHANGELOG.md+4 libs/prelude/Prelude/File.idr+7−6 src/Idris/Core/Execute.hs+1−1
CHANGELOG.md+4
@@ -1,5 +1,9 @@
11# New in next version
22
3+
4+## Library updates
5++ `openFile` opens the file in binary mode on Windows.
6+
37## Tool updates
48+ Modules no longer require building if imports have changed but all
59 interfaces (i.e. types for names declared `export` and definitions of names
libs/prelude/Prelude/File.idr+7−6
@@ -13,6 +13,7 @@ import Prelude.Basics
1313import Prelude.Interfaces
1414import Prelude.Either
1515import Prelude.Show
16+
1617import IO
1718
1819%access public export
@@ -108,12 +109,12 @@ validFile (FHandle h) = do x <- nullPtr h
108109data Mode = Read | WriteTruncate | Append | ReadWrite | ReadWriteTruncate | ReadAppend
109110
110111modeStr : Mode -> String
111−modeStr Read = "r"
112−modeStr WriteTruncate = "w"
113−modeStr Append = "a"
114−modeStr ReadWrite = "r+"
115−modeStr ReadWriteTruncate = "w+"
116−modeStr ReadAppend = "a+"
112+modeStr Read = "rb"
113+modeStr WriteTruncate = "wb"
114+modeStr Append = "ab"
115+modeStr ReadWrite = "rb+"
116+modeStr ReadWriteTruncate = "wb+"
117+modeStr ReadAppend = "ab+"
117118
118119||| Open a file
119120||| @ f the filename
src/Idris/Core/Execute.hs+1−1
@@ -345,7 +345,7 @@ execForeign env ctxt arity ty fn xs onfail
345345 = case (fileStr, modeStr) of
346346 (EConstant (Str f), EConstant (Str mode)) ->
347347 do f <- execIO $
348− catch (do let m = case mode of
348+ catch (do let m = case filter (/= 'b') mode of
349349 "r" -> Right ReadMode
350350 "w" -> Right WriteMode
351351 "a" -> Right AppendMode