@@ -92,7 +92,7 @@ data Mode = Read | Write | ReadWrite
9292
9393||| Open a file
9494||| @ f the filename
95−||| @ m the mode
95+||| @ m the mode; either Read, Write, or ReadWrite
9696openFile : (f : String) -> (m : Mode) -> IO (Either FileError File)
9797openFile f m = fopen f (modeStr m) where
9898 modeStr Read = "r"
@@ -143,6 +143,13 @@ fread (FHandle h) = do str <- do_fread h
143143 then return (Left FileReadError)
144144 else return (Right str)
145145
146+||| Read a line from a file
147+||| @h a file handle which must be open for reading
148+fGetLine : (h : File) -> IO (Either FileError String)
149+fGetLine = fread
150+
151+%deprecate fread "Use fGetLine instead"
152+
146153do_fwrite : Ptr -> String -> IO (Either FileError ())
147154do_fwrite h s = do res <- prim_fwrite h s
148155 if (res /= 0)
@@ -156,14 +163,31 @@ do_fwrite h s = do res <- prim_fwrite h s
156163fwrite : File -> String -> IO (Either FileError ())
157164fwrite (FHandle h) s = do_fwrite h s
158165
166+||| Write a line to a file
167+||| @h a file handle which must be open for writing
168+||| @str the line to write to the file
169+fPutStr : (h : File) -> (str : String) -> IO (Either FileError ())
170+fPutStr (FHandle h) s = do_fwrite h s
171+
172+fPutStrLn : File -> String -> IO (Either FileError ())
173+fPutStrLn (FHandle h) s = do_fwrite h (s ++ "\n")
174+
175+%deprecate fwrite "Use fPutStr instead"
176+
159177do_feof : Ptr -> IO Int
160178do_feof h = foreign FFI_C "fileEOF" (Ptr -> IO Int) h
161179
162180||| Check if a file handle has reached the end
163−feof : File -> IO Bool
164−feof (FHandle h) = do eof <- do_feof h
181+fEOF : File -> IO Bool
182+fEOF (FHandle h) = do eof <- do_feof h
165183 return (not (eof == 0))
166184
185+||| Check if a file handle has reached the end
186+feof : File -> IO Bool
187+feof = fEOF
188+
189+%deprecate feof "Use fEOF instead"
190+
167191fpoll : File -> IO Bool
168192fpoll (FHandle h) = do p <- foreign FFI_C "fpoll" (Ptr -> IO Int) h
169193 return (p > 0)
@@ -181,8 +205,8 @@ readFile fn = do Right h <- openFile fn Read
181205 partial
182206 readFile' : File -> String -> IO (Either FileError String)
183207 readFile' h contents =
184− do x <- feof h
185− if not x then do Right l <- fread h
208+ do x <- fEOF h
209+ if not x then do Right l <- fGetLine h
186210 | Left err => return (Left err)
187211 readFile' h (contents ++ l)
188212 else return (Right contents)
@@ -192,6 +216,6 @@ writeFile : (filepath : String) -> (contents : String) ->
192216 IO (Either FileError ())
193217writeFile fn contents = do
194218 Right h <- openFile fn Write | Left err => return (Left err)
195− Right () <- fwrite h contents | Left err => return (Left err)
219+ Right () <- fPutStr h contents | Left err => return (Left err)
196220 closeFile h
197221 return (Right ())