本文整理汇总了Golang中syscall.Wstat函数的典型用法代码示例。如果您正苦于以下问题:Golang Wstat函数的具体用法?Golang Wstat怎么用?Golang Wstat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Wstat函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: rename
func rename(oldname, newname string) error {
dirname := oldname[:lastIndex(oldname, '/')+1]
if hasPrefix(newname, dirname) {
newname = newname[len(dirname):]
} else {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
// If newname still contains slashes after removing the oldname
// prefix, the rename is cross-directory and must be rejected.
// This case is caught by d.Marshal below.
var d syscall.Dir
d.Null()
d.Name = newname
buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
n, err := d.Marshal(buf[:])
if err != nil {
return &LinkError{"rename", oldname, newname, err}
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &LinkError{"rename", oldname, newname, err}
}
return nil
}
示例2: Chmod
// Chmod changes the mode of the named file to mode.
func Chmod(name string, mode uint32) Error {
var d Dir
d.Null()
d.Mode = mode & 0777
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
return &PathError{"chmod", name, e}
}
return nil
}
示例3: Chtimes
// Chtimes changes the access and modification times of the named
// file, similar to the Unix utime() or utimes() functions.
//
// The argument times are in nanoseconds, although the underlying
// filesystem may truncate or round the values to a more
// coarse time unit.
func Chtimes(name string, atimeNs int64, mtimeNs int64) Error {
var d Dir
d.Null()
d.Atime = uint32(atimeNs / 1e9)
d.Mtime = uint32(mtimeNs / 1e9)
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
return &PathError{"chtimes", name, e}
}
return nil
}
示例4: ChownPlan9
// ChownPlan9 changes the uid and gid strings of the named file.
func ChownPlan9(name, uid, gid string) Error {
var d Dir
d.Null()
d.Uid = uid
d.Gid = gid
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
return &PathError{"chown_plan9", name, e}
}
return nil
}
示例5: Rename
// Rename renames a file.
func Rename(oldname, newname string) error {
var d syscall.Dir
d.Null()
d.Name = newname
buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"rename", oldname, err}
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &PathError{"rename", oldname, err}
}
return nil
}
示例6: Truncate
// Truncate changes the size of the named file.
// If the file is a symbolic link, it changes the size of the link's target.
// If there is an error, it will be of type *PathError.
func Truncate(name string, size int64) error {
var d syscall.Dir
d.Null()
d.Length = size
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"truncate", name, err}
}
if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"truncate", name, err}
}
return nil
}
示例7: Chmod
// Chmod changes the mode of the named file to mode.
func Chmod(name string, mode uint32) error {
var d Dir
var mask = ^uint32(0777)
d.Null()
odir, e := dirstat(name)
if iserror(e) {
return &PathError{"chmod", name, e}
}
d.Mode = (odir.Mode & mask) | (mode &^ mask)
if e := syscall.Wstat(name, pdir(nil, &d)); iserror(e) {
return &PathError{"chmod", name, e}
}
return nil
}
示例8: Chtimes
// Chtimes changes the access and modification times of the named
// file, similar to the Unix utime() or utimes() functions.
//
// The underlying filesystem may truncate or round the values to a
// less precise time unit.
// If there is an error, it will be of type *PathError.
func Chtimes(name string, atime time.Time, mtime time.Time) error {
var d syscall.Dir
d.Null()
d.Atime = uint32(atime.Unix())
d.Mtime = uint32(mtime.Unix())
var buf [syscall.STATFIXLEN]byte
n, err := d.Marshal(buf[:])
if err != nil {
return &PathError{"chtimes", name, err}
}
if err = syscall.Wstat(name, buf[:n]); err != nil {
return &PathError{"chtimes", name, err}
}
return nil
}
示例9: Chmod
// 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
}
示例10: rename
func rename(oldname, newname string) error {
dirname := oldname[:lastIndex(oldname, '/')+1]
if hasPrefix(newname, dirname) {
newname = newname[len(dirname):]
} else {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
// If newname still contains slashes after removing the oldname
// prefix, the rename is cross-directory and must be rejected.
if lastIndex(newname, '/') >= 0 {
return &LinkError{"rename", oldname, newname, ErrInvalid}
}
var d syscall.Dir
d.Null()
d.Name = newname
buf := make([]byte, syscall.STATFIXLEN+len(d.Name))
n, err := d.Marshal(buf[:])
if err != nil {
return &LinkError{"rename", oldname, newname, err}
}
// If newname already exists and is not a directory, rename replaces it.
f, err := Stat(dirname + newname)
if err == nil && !f.IsDir() {
Remove(dirname + newname)
}
if err = syscall.Wstat(oldname, buf[:n]); err != nil {
return &LinkError{"rename", oldname, newname, err}
}
return nil
}