From bfb8ad51d5151c34bd9d4101d0058fcc9eee7fe7 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Mon, 2 Mar 2015 10:43:39 -0500 Subject: [PATCH] os: set TMPDIR on darwin/arm This is a roll forward of 2adc3bd6ef84. It occurred to me that we will want this code on both darwin/arm and darwin/arm64. Removing _arm from the file name conveniently avoids #10032. Change-Id: I3a96a3e7020907d9307af8f696e26ad55b2060f0 Reviewed-on: https://go-review.googlesource.com/6460 Reviewed-by: Brad Fitzpatrick Run-TryBot: David Crawshaw --- src/os/file_darwin.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/os/file_darwin.go diff --git a/src/os/file_darwin.go b/src/os/file_darwin.go new file mode 100644 index 00000000000..ee3a954683a --- /dev/null +++ b/src/os/file_darwin.go @@ -0,0 +1,40 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build arm arm64 + +package os + +/* +#cgo CFLAGS: -x objective-c +#cgo LDFLAGS: -framework CoreFoundation -framework Foundation + +#include +#include +#include + +char tmpdir[MAXPATHLEN]; + +char* loadtmpdir() { + tmpdir[0] = 0; + CFStringRef path = (CFStringRef)NSTemporaryDirectory(); + CFStringGetCString(path, tmpdir, sizeof(tmpdir), kCFStringEncodingUTF8); + return tmpdir; +} +*/ +import "C" + +func init() { + if Getenv("TMPDIR") != "" { + return + } + dir := C.GoString(C.loadtmpdir()) + if len(dir) == 0 { + return + } + if dir[len(dir)-1] == '/' { + dir = dir[:len(dir)-1] + } + Setenv("TMPDIR", dir) +}