From 6b2d5e7aa8b0f420b202812dd9f80fa6483d75d0 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Mon, 26 Apr 2010 23:17:14 -0700 Subject: os, syscall: more mingw R=rsc, rsc1 CC=golang-dev http://codereview.appspot.com/878046 Committer: Russ Cox --- src/pkg/os/file_unix.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/pkg/os/file_unix.go') diff --git a/src/pkg/os/file_unix.go b/src/pkg/os/file_unix.go index 84ca48064..6cf266140 100644 --- a/src/pkg/os/file_unix.go +++ b/src/pkg/os/file_unix.go @@ -53,6 +53,17 @@ func (file *File) Close() Error { return err } +// Stat returns the FileInfo structure describing file. +// It returns the FileInfo and an error, if any. +func (file *File) Stat() (fi *FileInfo, err Error) { + var stat syscall.Stat_t + e := syscall.Fstat(file.fd, &stat) + if e != 0 { + return nil, &PathError{"stat", file.name, Errno(e)} + } + return fileInfoFromStat(file.name, new(FileInfo), &stat, &stat), nil +} + // Readdir reads the contents of the directory associated with file and // returns an array of up to count FileInfo structures, as would be returned // by Stat, in directory order. Subsequent calls on the same file will yield @@ -80,3 +91,12 @@ func (file *File) Readdir(count int) (fi []FileInfo, err Error) { } return } + +// Truncate changes the size of the named file. +// If the file is a symbolic link, it changes the size of the link's target. +func Truncate(name string, size int64) Error { + if e := syscall.Truncate(name, size); e != 0 { + return &PathError{"truncate", name, Errno(e)} + } + return nil +} -- cgit v1.2.3