os: TempDir(): obey TMPDIR on unix, TMP on win, etc

Uses upstream go code, lightly adjusted.

Adds smoke test.
This commit is contained in:
Dan Kegel
2021-11-21 17:28:40 -08:00
committed by Ron Evans
parent e354a3523b
commit 6b0f2cd697
5 changed files with 81 additions and 3 deletions
+12
View File
@@ -1,5 +1,9 @@
// +build darwin linux,!baremetal
// Portions copyright 2009 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.
package os
import (
@@ -26,6 +30,14 @@ func Pipe() (r *File, w *File, err error) {
return
}
func tempDir() string {
dir := Getenv("TMPDIR")
if dir == "" {
dir = "/tmp"
}
return dir
}
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
// It returns the number of bytes read and any error encountered, possibly io.EOF.
// At end of file, Pread returns 0, io.EOF.