Merge: src/model/model_index: model index uses BKTree
[nit.git] / lib / core / file.nit
index d8be114..ed4c6c8 100644 (file)
@@ -143,10 +143,15 @@ class FileReader
        end
 
        redef fun eof do
-               if lookahead_length != 0 then
-                       return false
+               var fl = _file
+               if fl == null then return true
+               if fl.address_is_null then return true
+               if last_error != null then return true
+               if super then
+                       if last_error != null then return true
+                       return fl.feof
                end
-               return _file.as(not null).feof
+               return false
        end
 
        # Open the file at `path` for reading.
@@ -301,6 +306,9 @@ redef class Int
        private fun fd_to_stream(mode: CString): NativeFile `{
                return fdopen((int)self, mode);
        `}
+
+       # Does the file descriptor `self` refer to a terminal?
+       fun isatty: Bool `{ return isatty(self); `}
 end
 
 # Constant for read-only file streams
@@ -1357,7 +1365,7 @@ redef class FlatString
                var p = last_byte
                var c = its[p]
                var st = _first_byte
-               while p >= st and c != '.'.ascii do
+               while p >= st and c != u'.' do
                        p -= 1
                        c = its[p]
                end
@@ -1374,7 +1382,7 @@ redef class FlatString
                var l = s.last_byte
                var its = s._items
                var min = s._first_byte
-               var sl = '/'.ascii
+               var sl = u'/'
                while l > min and its[l] == sl do l -= 1
                if l == min then return "/"
                var ns = l
@@ -1518,7 +1526,7 @@ private extern class NativeFile `{ FILE* `}
                return (long)res;
        `}
 
-       fun write_byte(value: Byte): Int `{
+       fun write_byte(value: Int): Int `{
                unsigned char b = (unsigned char)value;
                return fwrite(&b, 1, 1, self);
        `}