Skip to content

Commit

Permalink
windows: implement Ftruncate using a single syscall on Windows
Browse files Browse the repository at this point in the history
Ftruncate can be implemented on Windows using a single syscall. This
makes the implementation more efficient and less prone to races when
used in combination with other Seek calls.

Note that this is the x/sys counterpart for CL 618835.

Change-Id: Ie9be356bd953ccce85c0dd87a5dcc6ccf4fec464
Reviewed-on: https://go-review.googlesource.com/c/sys/+/621935
Reviewed-by: Alex Brainman <[email protected]>
Auto-Submit: Quim Muntal <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
  • Loading branch information
qmuntal authored and gopherbot committed Oct 28, 2024
1 parent cff53d5 commit d045236
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,20 +725,12 @@ func DurationSinceBoot() time.Duration {
}

func Ftruncate(fd Handle, length int64) (err error) {
curoffset, e := Seek(fd, 0, 1)
if e != nil {
return e
}
defer Seek(fd, curoffset, 0)
_, e = Seek(fd, length, 0)
if e != nil {
return e
type _FILE_END_OF_FILE_INFO struct {
EndOfFile int64
}
e = SetEndOfFile(fd)
if e != nil {
return e
}
return nil
var info _FILE_END_OF_FILE_INFO
info.EndOfFile = length
return SetFileInformationByHandle(fd, FileEndOfFileInfo, (*byte)(unsafe.Pointer(&info)), uint32(unsafe.Sizeof(info)))
}

func Gettimeofday(tv *Timeval) (err error) {
Expand Down

0 comments on commit d045236

Please sign in to comment.