From 0c54d58feaa6aa424076c6d44fbad624a2d7e271 Mon Sep 17 00:00:00 2001 From: Stefan Scherer Date: Wed, 18 Nov 2015 11:13:04 +0100 Subject: [PATCH] Move charsToString to architecture dependent source to fix casting problem Signed-off-by: Stefan Scherer --- platform/architecture_linux.go | 12 ------------ platform/utsname_int8.go | 18 ++++++++++++++++++ platform/utsname_uint8.go | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 platform/utsname_int8.go create mode 100644 platform/utsname_uint8.go diff --git a/platform/architecture_linux.go b/platform/architecture_linux.go index e732534..60314cf 100644 --- a/platform/architecture_linux.go +++ b/platform/architecture_linux.go @@ -14,15 +14,3 @@ func GetRuntimeArchitecture() (string, error) { } return charsToString(utsname.Machine), nil } - -func charsToString(ca [65]int8) string { - s := make([]byte, len(ca)) - var lens int - for ; lens < len(ca); lens++ { - if ca[lens] == 0 { - break - } - s[lens] = uint8(ca[lens]) - } - return string(s[0:lens]) -} diff --git a/platform/utsname_int8.go b/platform/utsname_int8.go new file mode 100644 index 0000000..5dcbadf --- /dev/null +++ b/platform/utsname_int8.go @@ -0,0 +1,18 @@ +// +build linux,386 linux,amd64 linux,arm64 +// see golang's sources src/syscall/ztypes_linux_*.go that use int8 + +package platform + +// Convert the OS/ARCH-specific utsname.Machine to string +// given as an array of signed int8 +func charsToString(ca [65]int8) string { + s := make([]byte, len(ca)) + var lens int + for ; lens < len(ca); lens++ { + if ca[lens] == 0 { + break + } + s[lens] = uint8(ca[lens]) + } + return string(s[0:lens]) +} diff --git a/platform/utsname_uint8.go b/platform/utsname_uint8.go new file mode 100644 index 0000000..c9875cf --- /dev/null +++ b/platform/utsname_uint8.go @@ -0,0 +1,18 @@ +// +build linux,arm linux,ppc64 linux,ppc64le s390x +// see golang's sources src/syscall/ztypes_linux_*.go that use uint8 + +package platform + +// Convert the OS/ARCH-specific utsname.Machine to string +// given as an array of unsigned uint8 +func charsToString(ca [65]uint8) string { + s := make([]byte, len(ca)) + var lens int + for ; lens < len(ca); lens++ { + if ca[lens] == 0 { + break + } + s[lens] = ca[lens] + } + return string(s[0:lens]) +}