]> Cypherpunks repositories - gostls13.git/commitdiff
os: fail if Open("") is called on windows
authorAlex Brainman <alex.brainman@gmail.com>
Sat, 26 Nov 2011 00:01:49 +0000 (11:01 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Sat, 26 Nov 2011 00:01:49 +0000 (11:01 +1100)
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5432071

src/pkg/os/file_windows.go
src/pkg/os/os_test.go

index 3a252fb2d8dbf1b9ceae5dc607193a110ae00ccc..81fdbe305126b38359aade44a46eb5e6eaff033b 100644 (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 {
index 7041136ec9eeb144d2903322c7d95b955124a7fa..c2fbc9fdd5cd5d46ec26739d7356eeac65945270 100644 (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()