From 7c1d49d90cbd91d7cc06d92686e2d09dd3dcac27 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 --- pkg/platform/architecture_linux.go | 12 ------------ pkg/platform/utsname_int8.go | 18 ++++++++++++++++++ pkg/platform/utsname_uint8.go | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 pkg/platform/utsname_int8.go create mode 100644 pkg/platform/utsname_uint8.go diff --git a/pkg/platform/architecture_linux.go b/pkg/platform/architecture_linux.go index e732534f33..60314cf577 100644 --- a/pkg/platform/architecture_linux.go +++ b/pkg/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/pkg/platform/utsname_int8.go b/pkg/platform/utsname_int8.go new file mode 100644 index 0000000000..5dcbadfdfe --- /dev/null +++ b/pkg/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/pkg/platform/utsname_uint8.go b/pkg/platform/utsname_uint8.go new file mode 100644 index 0000000000..c9875cf6e6 --- /dev/null +++ b/pkg/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]) +}