mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: fix file.read() (#15861)
This commit is contained in:
@ -237,11 +237,18 @@ pub fn (f &File) read(mut buf []u8) !int {
|
||||
if buf.len == 0 {
|
||||
return IError(Eof{})
|
||||
}
|
||||
nbytes := fread(buf.data, 1, buf.len, f.cfile) or {
|
||||
return IError(NotExpected{
|
||||
cause: 'unexpected error from fread'
|
||||
code: -1
|
||||
})
|
||||
nbytes := int(C.fread(buf.data, 1, buf.len, f.cfile))
|
||||
// if no bytes were read, check for errors and end-of-file.
|
||||
if nbytes <= 0 {
|
||||
if C.feof(f.cfile) != 0 {
|
||||
return IError(Eof{})
|
||||
}
|
||||
if C.ferror(f.cfile) != 0 {
|
||||
return IError(NotExpected{
|
||||
cause: 'unexpected error from fread'
|
||||
code: -1
|
||||
})
|
||||
}
|
||||
}
|
||||
return nbytes
|
||||
}
|
||||
|
Reference in New Issue
Block a user