// Chmod changes the mode of the named file to mode. // If the file is a symbolic link, it changes the mode of the link's target. // If there is an error, it will be of type *PathError. func Chmod(name string, mode FileMode) error { var d syscall.Dir odir, e := dirstat(name) if e != nil { return &PathError{"chmod", name, e} } d.Null() d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask var buf [syscall.STATFIXLEN]byte n, err := d.Marshal(buf[:]) if err != nil { return &PathError{"chmod", name, err} } if err = syscall.Wstat(name, buf[:n]); err != nil { return &PathError{"chmod", name, err} } return nil }
// Chmod changes the mode of the file to mode. // If there is an error, it will be of type *PathError. func (f *File) Chmod(mode FileMode) error { var d syscall.Dir odir, e := dirstat(f) if e != nil { return &PathError{"chmod", f.name, e} } d.Null() d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask var buf [syscall.STATFIXLEN]byte n, err := d.Marshal(buf[:]) if err != nil { return &PathError{"chmod", f.name, err} } if err = syscall.Fwstat(f.fd, buf[:n]); err != nil { return &PathError{"chmod", f.name, err} } return nil }