// 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 }
// 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. func (f *File) Truncate(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", f.name, err} } if err = syscall.Fwstat(f.fd, buf[:n]); err != nil { return &PathError{"truncate", f.name, err} } return nil }