Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.File.Read() yields os.EOF when len(buf) = 0 #2402

Closed
gopherbot opened this issue Oct 26, 2011 · 5 comments
Closed

os.File.Read() yields os.EOF when len(buf) = 0 #2402

gopherbot opened this issue Oct 26, 2011 · 5 comments

Comments

@gopherbot
Copy link
Contributor

by alexander.surma:

What steps will reproduce the problem?
1. f, _ := os.Open("some_file") // The file is not empty
2. buf := make([]byte, 0)
3. n, e := f.Read(buf)

What is the expected output?
n == 0 && e == nil

What do you see instead?
n == 0 && e == os.EOF

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
Mac OS X

Which revision are you using?  (hg identify)
7c1f789e6efd weekly/weekly.2011-10-26
@alexbrainman
Copy link
Member

Comment 1:

Please, do not ignore error returned by os.Open. Show us the error message instead:
...
f, e := os.Open("some_file")
fmt.Println(e)
...
Thank you.
Alex

@rsc
Copy link
Contributor

rsc commented Oct 27, 2011

Comment 2:

It's hard to say whether this is a bug or not.
The OS has returned something that amounts to EOF.
Russ

@gopherbot
Copy link
Contributor Author

Comment 3 by alexander.surma:

I did not ignore the error of os.Open(). Just in this example to keep it short. Opening
succeeds.
Also, if I do `buf := make([]byte, 1)`, I get data.
So, I just looked into $GOROOT/src/pkg/os/file.go which states in Line 72:
        if n == 0 && !iserror(e) {
                return 0, EOF
        }
This will of course occur, when I *want* to read 0 bytes. I personally think this is
rather unexpected behaviour.

@rsc
Copy link
Contributor

rsc commented Oct 31, 2011

Comment 4:

http://golang.org/cl/5298081

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Nov 1, 2011

Comment 5:

This issue was closed by revision 4853c51.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants