@@ -27,7 +27,7 @@ data File : Type where
27||| An error from a file operation
27||| An error from a file operation
28-- This is built in idris_mkFileError() in rts/idris_stdfgn.c. Make sure
28-- This is built in idris_mkFileError() in rts/idris_stdfgn.c. Make sure
29-- the values correspond!
29-- the values correspond!
31data FileError = GenericFileError Int -- errno
31data FileError = GenericFileError Int -- errno
32 | FileReadError
32 | FileReadError
33 | FileWriteError
33 | FileWriteError
@@ -102,10 +102,6 @@ validFile (FHandle h) = do x <- nullPtr h
102||| Modes for opening files
102||| Modes for opening files
103data Mode = Read | WriteTruncate | Append | ReadWrite | ReadWriteTruncate | ReadAppend
103data Mode = Read | WriteTruncate | Append | ReadWrite | ReadWriteTruncate | ReadAppend
106−Write = WriteTruncate
107−%deprecate Write "Please use WriteTruncate instead."
109modeStr : Mode -> String
105modeStr : Mode -> String
110modeStr Read = "r"
106modeStr Read = "r"
111modeStr WriteTruncate = "w"
107modeStr WriteTruncate = "w"
@@ -142,12 +138,12 @@ do_getFileSize h = foreign FFI_C "fileSize" (Ptr -> IO Int) h
143||| Return the size of a File
139||| Return the size of a File
144||| Returns an error if the File is not an ordinary file (e.g. a directory)
140||| Returns an error if the File is not an ordinary file (e.g. a directory)
145−||| Also note that this currently returns an Int, which may overflow if the
141+||| Also note that this currently returns an Int, which may overflow if the
146||| file is very big
142||| file is very big
148fileSize : File -> IO (Either FileError Int)
144fileSize : File -> IO (Either FileError Int)
149fileSize (FHandle h) = do s <- do_getFileSize h
145fileSize (FHandle h) = do s <- do_getFileSize h
150− if (s < 0)
146+ if (s < 0)
151 then do err <- getFileError
147 then do err <- getFileError
152 pure (Left err)
148 pure (Left err)
153 else pure (Right s)
149 else pure (Right s)
@@ -187,21 +183,16 @@ export
187pclose : File -> IO ()
183pclose : File -> IO ()
188pclose (FHandle h) = foreign FFI_C "pclose" (Ptr -> IO ()) h
184pclose (FHandle h) = foreign FFI_C "pclose" (Ptr -> IO ()) h
190−-- mkForeign (FFun "idris_readStr" [FPtr, FPtr] (FAny String))
194−fread : File -> IO (Either FileError String)
195−fread (FHandle h) = do str <- do_fread h
196− if !(ferror (FHandle h))
197− then pure (Left FileReadError)
198− else pure (Right str)
200||| Read a line from a file
187||| Read a line from a file
201||| @h a file handle which must be open for reading
188||| @h a file handle which must be open for reading
203fGetLine : (h : File) -> IO (Either FileError String)
190fGetLine : (h : File) -> IO (Either FileError String)
204−fGetLine = fread
191+fGetLine (FHandle h) = do
193+ if !(ferror (FHandle h))
194+ then pure (Left FileReadError)
195+ else pure (Right str)
206||| Read up to a number of characters from a file
197||| Read up to a number of characters from a file
207||| @h a file handle which must be open for reading
198||| @h a file handle which must be open for reading
@@ -212,7 +203,6 @@ fGetChars (FHandle h) len = do str <- do_freadChars h len
212 then pure (Left FileReadError)
203 then pure (Left FileReadError)
213 else pure (Right str)
204 else pure (Right str)
215−%deprecate fread "Use fGetLine instead"
218do_fwrite : Ptr -> String -> IO (Either FileError ())
208do_fwrite : Ptr -> String -> IO (Either FileError ())
@@ -225,10 +215,6 @@ do_fwrite h s = do res <- prim_fwrite h s
225 pure (Left err)
215 pure (Left err)
226 else pure (Right ())
216 else pure (Right ())
229−fwrite : File -> String -> IO (Either FileError ())
230−fwrite (FHandle h) s = do_fwrite h s
232||| Write a line to a file
218||| Write a line to a file
233||| @h a file handle which must be open for writing
219||| @h a file handle which must be open for writing
234||| @str the line to write to the file
220||| @str the line to write to the file
@@ -240,8 +226,6 @@ export
240fPutStrLn : File -> String -> IO (Either FileError ())
226fPutStrLn : File -> String -> IO (Either FileError ())
241fPutStrLn (FHandle h) s = do_fwrite h (s ++ "\n")
227fPutStrLn (FHandle h) s = do_fwrite h (s ++ "\n")
243−%deprecate fwrite "Use fPutStr instead"
246do_feof : Ptr -> IO Int
230do_feof : Ptr -> IO Int
247do_feof h = foreign FFI_C "fileEOF" (Ptr -> IO Int) h
231do_feof h = foreign FFI_C "fileEOF" (Ptr -> IO Int) h
@@ -252,13 +236,6 @@ fEOF : File -> IO Bool
252fEOF (FHandle h) = do eof <- do_feof h
236fEOF (FHandle h) = do eof <- do_feof h
253 pure (not (eof == 0))
237 pure (not (eof == 0))
255−||| Check if a file handle has reached the end
257−feof : File -> IO Bool
260−%deprecate feof "Use fEOF instead"
263fpoll : File -> IO Bool
240fpoll : File -> IO Bool
264fpoll (FHandle h) = do p <- foreign FFI_C "fpoll" (Ptr -> IO Int) h
241fpoll (FHandle h) = do p <- foreign FFI_C "fpoll" (Ptr -> IO Int) h