Closed IllusionMan1212 closed 2 weeks ago
This doesn't handle the case where len(p) == 0
.
The question is, how should that be handled?
This doesn't handle the case where
len(p) == 0
.The question is, how should that be handled?
It seems like the os package doesn't handle len(p) == 0
either.
Maybe len(p) == 0
should return io.Error.Short_Buffer
. What do you think?
Ignore package os
, it's awful.
But is that a short buffer or just an empty one? It's not necessarily an error.
IMO that should just return 0, nil
Reading into an empty buffer should always succeed, imo.
Personally I think an .Empty_Buffer
error would be better since you're not getting anything useful out of reading into an empty buffer. But if everyone thinks an empty read should succeed then I'm ok with that too.
I could update the condition to be if len(p) != 0 && n == 0 && ferr == nil
to distinguish EOF and empty reads.
It should be return 0, nil
on an empty buffer.
Changed the check for EOF to be in the _read
and _read_at
functions. This should be good to go now.
Current os2
file_stream
implementation forread
on linux never returns an EOF error when reaching the end of file.Linux's read syscall returns 0 read bytes if the end of file is reached: https://man7.org/linux/man-pages/man2/read.2.html
This also matches the implementation of the
os
package as evident bycore/os/stream.odin:30