diff --git a/examples/defer/defer.go b/examples/defer/defer.go
index 58836bc07..12fdae90a 100644
--- a/examples/defer/defer.go
+++ b/examples/defer/defer.go
@@ -8,6 +8,7 @@ package main
import (
"fmt"
"os"
+ "path/filepath"
)
// Suppose we wanted to create a file, write to it,
@@ -20,7 +21,8 @@ func main() {
// with `closeFile`. This will be executed at the end
// of the enclosing function (`main`), after
// `writeFile` has finished.
- f := createFile("/tmp/defer.txt")
+ path := filepath.Join(os.TempDir(), "defer.txt")
+ f := createFile(path)
defer closeFile(f)
writeFile(f)
}
diff --git a/examples/defer/defer.hash b/examples/defer/defer.hash
index 662ed7a0f..006ee7603 100644
--- a/examples/defer/defer.hash
+++ b/examples/defer/defer.hash
@@ -1,2 +1,2 @@
-249d0bc915e075a664be8b4e9115aa9568c8999e
-nhAzhDn_jga
+b3687ac676cbe21ebb53a8d864fc15649c27c4a8
+9_sJ5XnikSw
diff --git a/examples/reading-files/reading-files.go b/examples/reading-files/reading-files.go
index 1a863dc31..921eb9b1c 100644
--- a/examples/reading-files/reading-files.go
+++ b/examples/reading-files/reading-files.go
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"os"
+ "path/filepath"
)
// Reading files requires checking most calls for errors.
@@ -23,7 +24,8 @@ func main() {
// Perhaps the most basic file reading task is
// slurping a file's entire contents into memory.
- dat, err := os.ReadFile("/tmp/dat")
+ path := filepath.Join(os.TempDir(), "dat")
+ dat, err := os.ReadFile(path)
check(err)
fmt.Print(string(dat))
diff --git a/examples/reading-files/reading-files.hash b/examples/reading-files/reading-files.hash
index f1be9c3d2..5c5f9ae23 100644
--- a/examples/reading-files/reading-files.hash
+++ b/examples/reading-files/reading-files.hash
@@ -1,2 +1,2 @@
-db59474ee414017c3021706ceb35d5e355f967b3
-SKTzfpnV0To
+444f239565d06eabfc9fa9370db205fff292b238
+xKVFTA3G9k6
diff --git a/examples/writing-files/writing-files.go b/examples/writing-files/writing-files.go
index e8f3d7767..ba7070530 100644
--- a/examples/writing-files/writing-files.go
+++ b/examples/writing-files/writing-files.go
@@ -7,6 +7,7 @@ import (
"bufio"
"fmt"
"os"
+ "path/filepath"
)
func check(e error) {
@@ -20,11 +21,13 @@ func main() {
// To start, here's how to dump a string (or just
// bytes) into a file.
d1 := []byte("hello\ngo\n")
- err := os.WriteFile("/tmp/dat1", d1, 0644)
+ path1 := filepath.Join(os.TempDir(), "dat1")
+ err := os.WriteFile(path1, d1, 0644)
check(err)
// For more granular writes, open a file for writing.
- f, err := os.Create("/tmp/dat2")
+ path2 := filepath.Join(os.TempDir(), "dat2")
+ f, err := os.Create(path2)
check(err)
// It's idiomatic to defer a `Close` immediately
diff --git a/examples/writing-files/writing-files.hash b/examples/writing-files/writing-files.hash
index fcac248bb..249fc21d8 100644
--- a/examples/writing-files/writing-files.hash
+++ b/examples/writing-files/writing-files.hash
@@ -1,2 +1,2 @@
-e312100df0c063ecd65e7599653636188277b6a6
-Y12O-L_zFS1
+b93857561df33d0ed970d15e26f321627e770655
+iuKQDnKfl2T
diff --git a/public/defer b/public/defer
index cf758faee..178894d26 100644
--- a/public/defer
+++ b/public/defer
@@ -47,7 +47,7 @@ purposes of cleanup. defer is often used where e.g.

+ 
package main
defer is often used where e.g.
import (
"fmt"
"os"
+ "path/filepath"
)
@@ -89,7 +90,8 @@ of the enclosing function (main), after
f := createFile("/tmp/defer.txt")
+ path := filepath.Join(os.TempDir(), "defer.txt")
+ f := createFile(path)
defer closeFile(f)
writeFile(f)
}
@@ -187,7 +189,7 @@ after being written.