rsc.io/go@v0.0.0-20150416155037-e040fd465409/src/os/file_darwin.go (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build arm arm64
     6  
     7  package os
     8  
     9  /*
    10  #cgo CFLAGS: -x objective-c
    11  #cgo LDFLAGS: -framework CoreFoundation -framework Foundation
    12  
    13  #include <sys/param.h>
    14  #include <CoreFoundation/CFString.h>
    15  #include <Foundation/NSPathUtilities.h>
    16  
    17  char tmpdir[MAXPATHLEN];
    18  
    19  char* loadtmpdir() {
    20  	tmpdir[0] = 0;
    21  	CFStringRef path = (CFStringRef)NSTemporaryDirectory();
    22  	CFStringGetCString(path, tmpdir, sizeof(tmpdir), kCFStringEncodingUTF8);
    23  	return tmpdir;
    24  }
    25  */
    26  import "C"
    27  
    28  func init() {
    29  	if Getenv("TMPDIR") != "" {
    30  		return
    31  	}
    32  	dir := C.GoString(C.loadtmpdir())
    33  	if len(dir) == 0 {
    34  		return
    35  	}
    36  	if dir[len(dir)-1] == '/' {
    37  		dir = dir[:len(dir)-1]
    38  	}
    39  	Setenv("TMPDIR", dir)
    40  }