From 90cf820aafe8f7df39416fdbb932029ff99bd1ab Mon Sep 17 00:00:00 2001
From: Jan Mercl <0xjnml@gmail.com>
Date: Wed, 22 Mar 2017 22:50:52 +0100
Subject: [PATCH] TestPuch: Fix 32-bit issues. Closes #16.

---
 fileutil_arm.go     | 2 ++
 fileutil_darwin.go  | 2 ++
 fileutil_freebsd.go | 2 ++
 fileutil_linux.go   | 2 ++
 fileutil_netbsd.go  | 2 ++
 fileutil_openbsd.go | 2 ++
 fileutil_plan9.go   | 2 ++
 fileutil_solaris.go | 2 ++
 fileutil_windows.go | 2 ++
 punch_test.go       | 6 ++++++
 10 files changed, 24 insertions(+)

diff --git a/fileutil_arm.go b/fileutil_arm.go
index 9410d1b..c7b54f0 100644
--- a/fileutil_arm.go
+++ b/fileutil_arm.go
@@ -9,6 +9,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Not supported on ARM.
 func PunchHole(f *os.File, off, len int64) error {
diff --git a/fileutil_darwin.go b/fileutil_darwin.go
index c2b7628..5d939b2 100644
--- a/fileutil_darwin.go
+++ b/fileutil_darwin.go
@@ -11,6 +11,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Not supported on OSX.
 func PunchHole(f *os.File, off, len int64) error {
diff --git a/fileutil_freebsd.go b/fileutil_freebsd.go
index cefec0c..5a76993 100644
--- a/fileutil_freebsd.go
+++ b/fileutil_freebsd.go
@@ -11,6 +11,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Unimplemented on FreeBSD.
 func PunchHole(f *os.File, off, len int64) error {
diff --git a/fileutil_linux.go b/fileutil_linux.go
index 8babfc5..a894cb7 100644
--- a/fileutil_linux.go
+++ b/fileutil_linux.go
@@ -15,6 +15,8 @@ import (
 	"syscall"
 )
 
+const hasPunchHole = true
+
 func n(s []byte) byte {
 	for i, c := range s {
 		if c < '0' || c > '9' {
diff --git a/fileutil_netbsd.go b/fileutil_netbsd.go
index ca778d6..d641021 100644
--- a/fileutil_netbsd.go
+++ b/fileutil_netbsd.go
@@ -11,6 +11,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Similar to FreeBSD, this is
 // unimplemented.
diff --git a/fileutil_openbsd.go b/fileutil_openbsd.go
index 428171b..5c08989 100644
--- a/fileutil_openbsd.go
+++ b/fileutil_openbsd.go
@@ -9,6 +9,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Similar to FreeBSD, this is
 // unimplemented.
diff --git a/fileutil_plan9.go b/fileutil_plan9.go
index a2db64e..86787e5 100644
--- a/fileutil_plan9.go
+++ b/fileutil_plan9.go
@@ -9,6 +9,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Unimplemented on Plan 9.
 func PunchHole(f *os.File, off, len int64) error {
diff --git a/fileutil_solaris.go b/fileutil_solaris.go
index 61dfcde..3866686 100644
--- a/fileutil_solaris.go
+++ b/fileutil_solaris.go
@@ -11,6 +11,8 @@ import (
 	"os"
 )
 
+const hasPunchHole = false
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Not supported on Solaris.
 func PunchHole(f *os.File, off, len int64) error {
diff --git a/fileutil_windows.go b/fileutil_windows.go
index 3a81f2f..1e5d629 100644
--- a/fileutil_windows.go
+++ b/fileutil_windows.go
@@ -12,6 +12,8 @@ import (
 	"unsafe"
 )
 
+const hasPunchHole = true
+
 // PunchHole deallocates space inside a file in the byte range starting at
 // offset and continuing for len bytes. Not supported on Windows.
 func PunchHole(f *os.File, off, len int64) error {
diff --git a/punch_test.go b/punch_test.go
index 766f6f4..946ff5d 100644
--- a/punch_test.go
+++ b/punch_test.go
@@ -2,6 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
+// +build amd64 amd64p32 arm64 arm64be ppc64 ppc64le mips64 mips64le mips64p32 mips64p32le sparc64
+
 package fileutil
 
 import (
@@ -46,6 +48,10 @@ func TestPunch(t *testing.T) {
 		if buf[n-1] == 0 {
 			t.Errorf("%d. file at %d has been overwritten with 0!", i, j-1+n)
 		}
+		if !hasPunchHole {
+			continue
+		}
+
 		for k, v := range buf[1 : n-1] {
 			if v != 0 {
 				t.Errorf("%d. error reading file at %d got %d, want 0.", i, k, v)
-- 
2.11.0

