summaryrefslogtreecommitdiff
path: root/libgo/go/os/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/os/file.go')
-rw-r--r--libgo/go/os/file.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/libgo/go/os/file.go b/libgo/go/os/file.go
index c13babe5f7f..7995de79bfc 100644
--- a/libgo/go/os/file.go
+++ b/libgo/go/os/file.go
@@ -228,6 +228,9 @@ func (f *File) WriteString(s string) (n int, err error) {
// bits (before umask).
// If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error {
+ if runtime.GOOS == "windows" && isWindowsNulName(name) {
+ return &PathError{"mkdir", name, syscall.ENOTDIR}
+ }
e := syscall.Mkdir(fixLongPath(name), syscallMode(perm))
if e != nil {
@@ -247,7 +250,7 @@ func Mkdir(name string, perm FileMode) error {
return nil
}
-// setStickyBit adds ModeSticky to the permision bits of path, non atomic.
+// setStickyBit adds ModeSticky to the permission bits of path, non atomic.
func setStickyBit(name string) error {
fi, err := Stat(name)
if err != nil {
@@ -408,7 +411,7 @@ func UserCacheDir() (string, error) {
// subdirectory within this one and use that.
//
// On Unix systems, it returns $XDG_CONFIG_HOME as specified by
-// https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html if
+// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if
// non-empty, else $HOME/.config.
// On Darwin, it returns $HOME/Library/Application Support.
// On Windows, it returns %AppData%.
@@ -472,8 +475,6 @@ func UserHomeDir() (string, error) {
}
// On some geese the home directory is not always defined.
switch runtime.GOOS {
- case "nacl":
- return "/", nil
case "android":
return "/sdcard", nil
case "darwin":
@@ -560,3 +561,21 @@ func (f *File) SyscallConn() (syscall.RawConn, error) {
}
return newRawConn(f)
}
+
+// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
+// True is returned if name is 'NUL' whatever the case.
+func isWindowsNulName(name string) bool {
+ if len(name) != 3 {
+ return false
+ }
+ if name[0] != 'n' && name[0] != 'N' {
+ return false
+ }
+ if name[1] != 'u' && name[1] != 'U' {
+ return false
+ }
+ if name[2] != 'l' && name[2] != 'L' {
+ return false
+ }
+ return true
+}