mirror of
https://github.com/golang/go
synced 2024-11-25 08:47:56 -07:00
syscall: fix windows SetFileAttributes
R=golang-dev, rsc, hector CC=golang-dev, mattn https://golang.org/cl/4180052
This commit is contained in:
parent
6cf98a4553
commit
946cdf82bc
@ -154,7 +154,7 @@ func NewCallback(fn interface{}) uintptr
|
||||
//sys SetEnvironmentVariable(name *uint16, value *uint16) (errno int) = kernel32.SetEnvironmentVariableW
|
||||
//sys SetFileTime(handle int32, ctime *Filetime, atime *Filetime, wtime *Filetime) (errno int)
|
||||
//sys GetFileAttributes(name *uint16) (attrs uint32, errno int) [failretval==INVALID_FILE_ATTRIBUTES] = kernel32.GetFileAttributesW
|
||||
//sys SetFileAttributes(name *uint16, attrs uint32) (errno int) [failretval==INVALID_FILE_ATTRIBUTES] = kernel32.SetFileAttributesW
|
||||
//sys SetFileAttributes(name *uint16, attrs uint32) (errno int) = kernel32.SetFileAttributesW
|
||||
//sys GetCommandLine() (cmd *uint16) = kernel32.GetCommandLineW
|
||||
//sys CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, errno int) [failretval==nil] = shell32.CommandLineToArgvW
|
||||
//sys LocalFree(hmem uint32) (handle uint32, errno int) [failretval!=0]
|
||||
@ -471,6 +471,23 @@ func Fsync(fd int) (errno int) {
|
||||
return FlushFileBuffers(int32(fd))
|
||||
}
|
||||
|
||||
func Chmod(path string, mode uint32) (errno int) {
|
||||
if mode == 0 {
|
||||
return EINVAL
|
||||
}
|
||||
p := StringToUTF16Ptr(path)
|
||||
attrs, e := GetFileAttributes(p)
|
||||
if e != 0 {
|
||||
return e
|
||||
}
|
||||
if mode&S_IWRITE != 0 {
|
||||
attrs &^= FILE_ATTRIBUTE_READONLY
|
||||
} else {
|
||||
attrs |= FILE_ATTRIBUTE_READONLY
|
||||
}
|
||||
return SetFileAttributes(p, attrs)
|
||||
}
|
||||
|
||||
// net api calls
|
||||
|
||||
//sys WSAStartup(verreq uint32, data *WSAData) (sockerrno int) = wsock32.WSAStartup
|
||||
@ -731,26 +748,6 @@ func Link(oldpath, newpath string) (errno int) { return EWINDOWS }
|
||||
func Symlink(path, link string) (errno int) { return EWINDOWS }
|
||||
func Readlink(path string, buf []byte) (n int, errno int) { return 0, EWINDOWS }
|
||||
|
||||
func Chmod(path string, mode uint32) (errno int) {
|
||||
attrs, errno := GetFileAttributes(StringToUTF16Ptr(path))
|
||||
if errno != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if mode == 0 {
|
||||
return EINVAL
|
||||
}
|
||||
|
||||
if mode&S_IWRITE != 0 {
|
||||
attrs &^= FILE_ATTRIBUTE_READONLY
|
||||
} else if attrs&FILE_ATTRIBUTE_READONLY == 0 {
|
||||
attrs |= FILE_ATTRIBUTE_READONLY
|
||||
}
|
||||
|
||||
errno = SetFileAttributes(StringToUTF16Ptr(path), attrs)
|
||||
return
|
||||
}
|
||||
|
||||
func Fchmod(fd int, mode uint32) (errno int) { return EWINDOWS }
|
||||
func Chown(path string, uid int, gid int) (errno int) { return EWINDOWS }
|
||||
func Lchown(path string, uid int, gid int) (errno int) { return EWINDOWS }
|
||||
|
@ -808,8 +808,8 @@ func GetFileAttributes(name *uint16) (attrs uint32, errno int) {
|
||||
}
|
||||
|
||||
func SetFileAttributes(name *uint16, attrs uint32) (errno int) {
|
||||
r0, _, e1 := Syscall(procSetFileAttributesW, 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
|
||||
if int(r0) == 0 {
|
||||
r1, _, e1 := Syscall(procSetFileAttributesW, 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
|
||||
if int(r1) == 0 {
|
||||
if e1 != 0 {
|
||||
errno = int(e1)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user