// TempDir returns the default directory to use for temporary files. func TempDir() string { const pathSep = '\\' dirw := make([]uint16, syscall.MAX_PATH) n, _ := syscall.GetTempPath(uint32(len(dirw)), &dirw[0]) if n > uint32(len(dirw)) { dirw = make([]uint16, n) n, _ = syscall.GetTempPath(uint32(len(dirw)), &dirw[0]) if n > uint32(len(dirw)) { n = 0 } } if n > 0 && dirw[n-1] == pathSep { n-- } return string(utf16.Decode(dirw[0:n])) }
// TempDir returns the default directory to use for temporary files. 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 > 0 && b[n-1] == '\\' { n-- } return string(utf16.Decode(b[:n])) } }