return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666)
}
+// OpenFile is the generalized open call; most users will use Open
+// or Create instead. It opens the named file with specified flag
+// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
+// methods on the returned File can be used for I/O.
+// If there is an error, it will be of type *PathError.
+func OpenFile(name string, flag int, perm FileMode) (*File, error) {
+ testlog.Open(name)
+ return openFileNolog(name, flag, perm)
+}
+
// lstat is overridden in tests.
var lstat = Lstat
import (
"internal/poll"
- "internal/testlog"
"io"
"runtime"
"syscall"
return
}
-// OpenFile is the generalized open call; most users will use Open
-// or Create instead. It opens the named file with specified flag
-// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
-// methods on the returned File can be used for I/O.
-// If there is an error, it will be of type *PathError.
-func OpenFile(name string, flag int, perm FileMode) (*File, error) {
- testlog.Open(name)
-
+// openFileNolog is the Plan 9 implementation of OpenFile.
+func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
var (
fd int
e error
import (
"internal/poll"
- "internal/testlog"
"runtime"
"syscall"
)
// On Unix-like systems, it is "/dev/null"; on Windows, "NUL".
const DevNull = "/dev/null"
-// OpenFile is the generalized open call; most users will use Open
-// or Create instead. It opens the named file with specified flag
-// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
-// methods on the returned File can be used for I/O.
-// If there is an error, it will be of type *PathError.
-func OpenFile(name string, flag int, perm FileMode) (*File, error) {
- testlog.Open(name)
-
+// openFileNolog is the Unix implementation of OpenFile.
+func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
chmod := false
if !supportsCreateWithStickyBit && flag&O_CREATE != 0 && perm&ModeSticky != 0 {
if _, err := Stat(name); IsNotExist(err) {
import (
"internal/poll"
"internal/syscall/windows"
- "internal/testlog"
"runtime"
"syscall"
"unicode/utf16"
return f, nil
}
-// OpenFile is the generalized open call; most users will use Open
-// or Create instead. It opens the named file with specified flag
-// (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
-// methods on the returned File can be used for I/O.
-// If there is an error, it will be of type *PathError.
-func OpenFile(name string, flag int, perm FileMode) (*File, error) {
- testlog.Open(name)
-
+// openFileNolog is the Windows implementation of OpenFile.
+func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
if name == "" {
return nil, &PathError{"open", name, syscall.ENOENT}
}
// Clumsy but widespread kludge:
// if $PWD is set and matches ".", use it.
- dot, err := Stat(".")
+ dot, err := statNolog(".")
if err != nil {
return "", err
}
dir = Getenv("PWD")
if len(dir) > 0 && dir[0] == '/' {
- d, err := Stat(dir)
+ d, err := statNolog(dir)
if err == nil && SameFile(dot, d) {
return dir, nil
}
dir = getwdCache.dir
getwdCache.Unlock()
if len(dir) > 0 {
- d, err := Stat(dir)
+ d, err := statNolog(dir)
if err == nil && SameFile(dot, d) {
return dir, nil
}
// Root is a special case because it has no parent
// and ends in a slash.
- root, err := Stat("/")
+ root, err := statNolog("/")
if err != nil {
// Can't stat root - no hope.
return "", err
if len(parent) >= 1024 { // Sanity check
return "", syscall.ENAMETOOLONG
}
- fd, err := Open(parent)
+ fd, err := openFileNolog(parent, O_RDONLY, 0)
if err != nil {
return "", err
}
return "", err
}
for _, name := range names {
- d, _ := Lstat(parent + "/" + name)
+ d, _ := lstatNolog(parent + "/" + name)
if SameFile(d, dot) {
dir = "/" + name + dir
goto Found
--- /dev/null
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package os
+
+import "internal/testlog"
+
+// Stat returns a FileInfo describing the named file.
+// If there is an error, it will be of type *PathError.
+func Stat(name string) (FileInfo, error) {
+ testlog.Stat(name)
+ return statNolog(name)
+}
+
+// Lstat returns a FileInfo describing the named file.
+// If the file is a symbolic link, the returned FileInfo
+// describes the symbolic link. Lstat makes no attempt to follow the link.
+// If there is an error, it will be of type *PathError.
+func Lstat(name string) (FileInfo, error) {
+ testlog.Stat(name)
+ return lstatNolog(name)
+}
package os
import (
- "internal/testlog"
"syscall"
"time"
)
return nil, &PathError{"stat", name, err}
}
-// Stat returns a FileInfo describing the named file.
-// If there is an error, it will be of type *PathError.
-func Stat(name string) (FileInfo, error) {
- testlog.Stat(name)
+// statNolog implements Stat for Plan 9.
+func statNolog(name string) (FileInfo, error) {
d, err := dirstat(name)
if err != nil {
return nil, err
return fileInfoFromStat(d), nil
}
-// Lstat returns a FileInfo describing the named file.
-// If the file is a symbolic link, the returned FileInfo
-// describes the symbolic link. Lstat makes no attempt to follow the link.
-// If there is an error, it will be of type *PathError.
-func Lstat(name string) (FileInfo, error) {
- return Stat(name)
+// lstatNolog implements Lstat for Plan 9.
+func lstatNolog(name string) (FileInfo, error) {
+ return statNolog(name)
}
// For testing.
package os
import (
- "internal/testlog"
"syscall"
)
return &fs, nil
}
-// Stat returns a FileInfo describing the named file.
-// If there is an error, it will be of type *PathError.
-func Stat(name string) (FileInfo, error) {
- testlog.Stat(name)
+// statNolog stats a file with no test logging.
+func statNolog(name string) (FileInfo, error) {
var fs fileStat
err := syscall.Stat(name, &fs.sys)
if err != nil {
return &fs, nil
}
-// Lstat returns a FileInfo describing the named file.
-// If the file is a symbolic link, the returned FileInfo
-// describes the symbolic link. Lstat makes no attempt to follow the link.
-// If there is an error, it will be of type *PathError.
-func Lstat(name string) (FileInfo, error) {
- testlog.Stat(name)
+// lstatNolog lstats a file with no test logging.
+func lstatNolog(name string) (FileInfo, error) {
var fs fileStat
err := syscall.Lstat(name, &fs.sys)
if err != nil {
import (
"internal/syscall/windows"
- "internal/testlog"
"syscall"
"unsafe"
)
}, nil
}
-// Stat returns a FileInfo structure describing the named file.
-// If there is an error, it will be of type *PathError.
-func Stat(name string) (FileInfo, error) {
- testlog.Stat(name)
+// statNolog implements Stat for Windows.
+func statNolog(name string) (FileInfo, error) {
if len(name) == 0 {
return nil, &PathError{"Stat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
}
}, nil
}
-// Lstat returns the FileInfo structure describing the named file.
-// If the file is a symbolic link, the returned FileInfo
-// describes the symbolic link. Lstat makes no attempt to follow the link.
-// If there is an error, it will be of type *PathError.
-func Lstat(name string) (FileInfo, error) {
- testlog.Stat(name)
+// lstatNolog implements Lstat for Windows.
+func lstatNolog(name string) (FileInfo, error) {
if len(name) == 0 {
return nil, &PathError{"Lstat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
}