1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:14:41 -07:00

os: fail if Open("") is called on windows

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5432071
This commit is contained in:
Alex Brainman 2011-11-26 11:01:49 +11:00
parent 5519b5d716
commit e38a1053a9
2 changed files with 11 additions and 0 deletions

View File

@ -89,6 +89,9 @@ func openDir(name string) (file *File, err error) {
// methods on the returned File can be used for I/O.
// It returns the File and an error, if any.
func OpenFile(name string, flag int, perm uint32) (file *File, err error) {
if name == "" {
return nil, &PathError{"open", name, syscall.ENOENT}
}
// TODO(brainman): not sure about my logic of assuming it is dir first, then fall back to file
r, e := openDir(name)
if e == nil {

View File

@ -901,6 +901,14 @@ func TestOpenError(t *testing.T) {
}
}
func TestOpenNoName(t *testing.T) {
f, err := Open("")
if err == nil {
t.Fatal(`Open("") succeeded`)
f.Close()
}
}
func run(t *testing.T, cmd []string) string {
// Run /bin/hostname and collect output.
r, w, err := Pipe()