lib/std: handle read errors in FileReader
authorJean Privat <jean@pryen.org>
Tue, 21 Jul 2015 13:11:19 +0000 (09:11 -0400)
committerJean Privat <jean@pryen.org>
Tue, 21 Jul 2015 13:22:08 +0000 (09:22 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/file.nit

index 84bedbc..3a1eb1d 100644 (file)
@@ -127,6 +127,10 @@ class FileReader
        redef fun fill_buffer
        do
                var nb = _file.io_read(_buffer, _buffer_capacity)
+               if last_error == null and _file.ferror then
+                       last_error = new IOError("Cannot read `{path.as(not null)}`: {sys.errno.strerror}")
+                       end_reached = true
+               end
                if nb <= 0 then
                        end_reached = true
                        nb = 0
@@ -1333,6 +1337,8 @@ private extern class NativeFile `{ FILE* `}
                return 0;
        `}
 
+       fun ferror: Bool `{ return ferror(self); `}
+
        fun fileno: Int `{ return fileno(self); `}
 
        # Flushes the buffer, forcing the write operation