mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 06:46:44 -04:00
unix: offs2lohi should shift by bits, not bytes
Fixes golang/go#57291 Change-Id: I212ab8a9f47563d9c124a0f20c17df35d7aa8e6d Reviewed-on: https://go-review.googlesource.com/c/sys/+/457315 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Gopher Robot
parent
cffae8ece4
commit
72f772c4d7
@@ -1099,3 +1099,36 @@ func TestIoctlFileDedupeRange(t *testing.T) {
|
||||
dedupe.Info[1].Bytes_deduped, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPwritevOffsets tests golang.org/issues/57291 where
|
||||
// offs2lohi was shifting by the size of long in bytes, not bits.
|
||||
func TestPwritevOffsets(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "x.txt")
|
||||
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { f.Close() })
|
||||
|
||||
const (
|
||||
off = 20
|
||||
)
|
||||
b := [][]byte{{byte(0)}}
|
||||
n, err := unix.Pwritev(int(f.Fd()), b, off)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != len(b) {
|
||||
t.Fatalf("expected to write %d, wrote %d", len(b), n)
|
||||
}
|
||||
|
||||
info, err := f.Stat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := off + int64(len(b))
|
||||
if info.Size() != want {
|
||||
t.Fatalf("expected size to be %d, got %d", want, info.Size())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user