diff options
Diffstat (limited to 'src/os/file_unix.go')
-rw-r--r-- | src/os/file_unix.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/os/file_unix.go b/src/os/file_unix.go index badfc71ff..ef7abcbac 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -125,6 +125,25 @@ func Readlink(name string) (string, error) { } } +// Truncate changes the size of the file. +// It does not change the I/O offset. +// If there is an error, it will be of type *PathError. +// Alternatively just use 'raw' syscall by file name +func (f *File) Truncate(size int64) (err error) { + if f.handle == nil { + return ErrClosed + } + + e := ignoringEINTR(func() error { + return syscall.Truncate(f.name, size) + }) + + if e != nil { + return &PathError{Op: "truncate", Path: f.name, Err: e} + } + return +} + // ReadAt reads up to len(b) bytes from the File starting at the given absolute offset. // It returns the number of bytes read and any error encountered, possibly io.EOF. // At end of file, Pread returns 0, io.EOF. |