當前位置: 首頁>>代碼示例>>Golang>>正文


Golang syscall.Wstat函數代碼示例

本文整理匯總了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
}
開發者ID:Ericean,項目名稱:go,代碼行數:27,代碼來源:file_plan9.go

示例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
}
開發者ID:go-nosql,項目名稱:golang,代碼行數:12,代碼來源:file_plan9.go

示例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
}
開發者ID:go-nosql,項目名稱:golang,代碼行數:18,代碼來源:file_plan9.go

示例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
}
開發者ID:go-nosql,項目名稱:golang,代碼行數:13,代碼來源:file_plan9.go

示例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
}
開發者ID:kostyll,項目名稱:gccpy,代碼行數:17,代碼來源:file_plan9.go

示例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
}
開發者ID:kostyll,項目名稱:gccpy,代碼行數:19,代碼來源:file_plan9.go

示例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
}
開發者ID:aubonbeurre,項目名稱:gcc,代碼行數:17,代碼來源:file_plan9.go

示例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
}
開發者ID:kostyll,項目名稱:gccpy,代碼行數:23,代碼來源:file_plan9.go

示例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
}
開發者ID:kostyll,項目名稱:gccpy,代碼行數:23,代碼來源:file_plan9.go

示例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
}
開發者ID:achanda,項目名稱:go,代碼行數:36,代碼來源:file_plan9.go


注:本文中的syscall.Wstat函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。