@@ -55,6 +55,19 @@ func NewFile(fd uintptr, name string) *File {
55
55
return & File {& file {handle : unixFileHandle (fd ), name : name }}
56
56
}
57
57
58
+ // Truncate changes the size of the named file.
59
+ // If the file is a symbolic link, it changes the size of the link's target.
60
+ // If there is an error, it will be of type *PathError.
61
+ func Truncate (name string , size int64 ) error {
62
+ e := ignoringEINTR (func () error {
63
+ return syscall .Truncate (name , size )
64
+ })
65
+ if e != nil {
66
+ return & PathError {Op : "truncate" , Path : name , Err : e }
67
+ }
68
+ return nil
69
+ }
70
+
58
71
func Pipe () (r * File , w * File , err error ) {
59
72
var p [2 ]int
60
73
err = handleSyscallError (syscall .Pipe2 (p [:], syscall .O_CLOEXEC ))
@@ -134,14 +147,7 @@ func (f *File) Truncate(size int64) (err error) {
134
147
return ErrClosed
135
148
}
136
149
137
- e := ignoringEINTR (func () error {
138
- return syscall .Truncate (f .name , size )
139
- })
140
-
141
- if e != nil {
142
- return & PathError {Op : "truncate" , Path : f .name , Err : e }
143
- }
144
- return
150
+ return Truncate (f .name , size )
145
151
}
146
152
147
153
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
0 commit comments