]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: fix Ftruncate under linux/arm5
authorDave Cheney <dave@cheney.net>
Fri, 22 Apr 2011 18:44:18 +0000 (14:44 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 22 Apr 2011 18:44:18 +0000 (14:44 -0400)
Fixes #1714.

R=rsc, bradfitzgo
CC=golang-dev
https://golang.org/cl/4441056

src/pkg/os/os_test.go
src/pkg/syscall/syscall_linux_arm.go
src/pkg/syscall/zsyscall_linux_arm.go

index 4c9feab1ceb08ae303a84f0e17e60c4b27f07864..65475c118aec18b487da65ab93e964e2b3854e3e 100644 (file)
@@ -567,8 +567,8 @@ func checkSize(t *testing.T, f *File, size int64) {
        }
 }
 
-func TestTruncate(t *testing.T) {
-       f := newFile("TestTruncate", t)
+func TestFTruncate(t *testing.T) {
+       f := newFile("TestFTruncate", t)
        defer Remove(f.Name())
        defer f.Close()
 
@@ -585,6 +585,24 @@ func TestTruncate(t *testing.T) {
        checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
 }
 
+func TestTruncate(t *testing.T) {
+       f := newFile("TestTruncate", t)
+       defer Remove(f.Name())
+       defer f.Close()
+
+       checkSize(t, f, 0)
+       f.Write([]byte("hello, world\n"))
+       checkSize(t, f, 13)
+       Truncate(f.Name(), 10)
+       checkSize(t, f, 10)
+       Truncate(f.Name(), 1024)
+       checkSize(t, f, 1024)
+       Truncate(f.Name(), 0)
+       checkSize(t, f, 0)
+       f.Write([]byte("surprise!"))
+       checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
+}
+
 // Use TempDir() to make sure we're on a local file system,
 // so that timings are not distorted by latency and caching.
 // On NFS, timings can be off due to caching of meta-data on
index 6472c4db54fe98ff1c1494838a87bb05b0e9c765..4587458859492364b5241b9180109cfc85924765 100644 (file)
@@ -24,7 +24,6 @@ func NsecToTimeval(nsec int64) (tv Timeval) {
 }
 
 // Pread and Pwrite are special: they insert padding before the int64.
-// (Ftruncate and truncate are not; go figure.)
 
 func Pread(fd int, p []byte, offset int64) (n int, errno int) {
        var _p0 unsafe.Pointer
@@ -48,6 +47,20 @@ func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
        return
 }
 
+func Ftruncate(fd int, length int64) (errno int) {
+       // ARM EABI requires 64-bit arguments should be put in a pair
+       // of registers from an even register number.
+       _, _, e1 := Syscall6(SYS_FTRUNCATE64, uintptr(fd), 0, uintptr(length), uintptr(length>>32), 0, 0)
+       errno = int(e1)
+       return
+}
+
+func Truncate(path string, length int64) (errno int) {
+       _, _, e1 := Syscall6(SYS_TRUNCATE64, uintptr(unsafe.Pointer(StringBytePtr(path))), 0, uintptr(length), uintptr(length>>32), 0, 0)
+       errno = int(e1)
+       return
+}
+
 // Seek is defined in assembly.
 
 func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
@@ -72,7 +85,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
 //sys  Fchown(fd int, uid int, gid int) (errno int)
 //sys  Fstat(fd int, stat *Stat_t) (errno int) = SYS_FSTAT64
 //sys  Fstatfs(fd int, buf *Statfs_t) (errno int) = SYS_FSTATFS64
-//sys  Ftruncate(fd int, length int64) (errno int) = SYS_FTRUNCATE64
 //sysnb        Getegid() (egid int)
 //sysnb        Geteuid() (euid int)
 //sysnb        Getgid() (gid int)
@@ -92,7 +104,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, errno int)
 //sys  Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, errno int)
 //sys  Stat(path string, stat *Stat_t) (errno int) = SYS_STAT64
 //sys  Statfs(path string, buf *Statfs_t) (errno int) = SYS_STATFS64
-//sys  Truncate(path string, length int64) (errno int) = SYS_TRUNCATE64
 
 // Vsyscalls on amd64.
 //sysnb        Gettimeofday(tv *Timeval) (errno int)
index 43b84d98c5d1ce56c4ae72b6834d78b0c2100de1..f41240d5c4663a2448a38cf471233b115a0a175c 100644 (file)
@@ -970,14 +970,6 @@ func Fstatfs(fd int, buf *Statfs_t) (errno int) {
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func Ftruncate(fd int, length int64) (errno int) {
-       _, _, e1 := Syscall(SYS_FTRUNCATE64, uintptr(fd), uintptr(length>>32), uintptr(length))
-       errno = int(e1)
-       return
-}
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Getegid() (egid int) {
        r0, _, _ := RawSyscall(SYS_GETEGID, 0, 0, 0)
        egid = int(r0)
@@ -1132,14 +1124,6 @@ func Statfs(path string, buf *Statfs_t) (errno int) {
 
 // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
 
-func Truncate(path string, length int64) (errno int) {
-       _, _, e1 := Syscall(SYS_TRUNCATE64, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(length>>32), uintptr(length))
-       errno = int(e1)
-       return
-}
-
-// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
-
 func Gettimeofday(tv *Timeval) (errno int) {
        _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0)
        errno = int(e1)