mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-14 07:53:40 +00:00
os: TempDir(): obey TMPDIR on unix, TMP on win, etc
Uses upstream go code, lightly adjusted. Adds smoke test.
This commit is contained in:
+27
-1
@@ -1,8 +1,16 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
// 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 "syscall"
|
||||
import (
|
||||
"syscall"
|
||||
"unicode/utf16"
|
||||
)
|
||||
|
||||
type syscallFd = syscall.Handle
|
||||
|
||||
@@ -23,6 +31,24 @@ func Pipe() (r *File, w *File, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func tempDir() string {
|
||||
n := uint32(syscall.MAX_PATH)
|
||||
for {
|
||||
b := make([]uint16, n)
|
||||
n, _ = syscall.GetTempPath(uint32(len(b)), &b[0])
|
||||
if n > uint32(len(b)) {
|
||||
continue
|
||||
}
|
||||
if n == 3 && b[1] == ':' && b[2] == '\\' {
|
||||
// Do nothing for path, like C:\.
|
||||
} else if n > 0 && b[n-1] == '\\' {
|
||||
// Otherwise remove terminating \.
|
||||
n--
|
||||
}
|
||||
return string(utf16.Decode(b[:n]))
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
Reference in New Issue
Block a user