Skip to content

Commit

Permalink
chore: remove refs to deprecated io/ioutil (#899)
Browse files Browse the repository at this point in the history
Signed-off-by: guoguangwu <[email protected]>
  • Loading branch information
testwill authored Jun 3, 2024
1 parent 9839acd commit f296f6e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
5 changes: 2 additions & 3 deletions ast/character_literal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ast
import (
"fmt"
"github.com/elliotchance/c2go/cc"
"io/ioutil"
"os"
"path"
"testing"
Expand Down Expand Up @@ -347,14 +346,14 @@ func TestCharacterLiteralRepairFromSource(t *testing.T) {

func prepareRepairFromSourceTest(t *testing.T, fileContent string, test func(filePath string)) {
cc.ResetCache()
dir, err := ioutil.TempDir("", "c2go")
dir, err := os.MkdirTemp("", "c2go")
if err != nil {
t.Fatal(fmt.Errorf("Cannot create temp folder: %v", err))
}
defer os.RemoveAll(dir) // clean up

ppFilePath := path.Join(dir, "pp.c")
err = ioutil.WriteFile(ppFilePath, []byte(fileContent), 0644)
err = os.WriteFile(ppFilePath, []byte(fileContent), 0644)
if err != nil {
t.Fatal(fmt.Errorf("writing to %s failed: %v", ppFilePath, err))
}
Expand Down
4 changes: 2 additions & 2 deletions cc/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cc

import (
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/elliotchance/c2go/util"
Expand All @@ -26,7 +26,7 @@ func GetLineFromPreprocessedFile(inputFilePath, filePath string, lineNumber int)
if fileCache == nil {
fileCache = map[string]map[int]string{}

inputFile, err := ioutil.ReadFile(inputFilePath)
inputFile, err := os.ReadFile(inputFilePath)
if err != nil {
return "", err
}
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -198,14 +197,14 @@ func Start(args ProgramArgs) (err error) {
if args.verbose {
fmt.Println("Writing preprocessor ...")
}
dir, err := ioutil.TempDir("", "c2go")
dir, err := os.MkdirTemp("", "c2go")
if err != nil {
return fmt.Errorf("Cannot create temp folder: %v", err)
}
defer os.RemoveAll(dir) // clean up

ppFilePath := path.Join(dir, "pp.c")
err = ioutil.WriteFile(ppFilePath, pp, 0644)
err = os.WriteFile(ppFilePath, pp, 0644)
if err != nil {
return fmt.Errorf("writing to %s failed: %v", ppFilePath, err)
}
Expand Down Expand Up @@ -304,7 +303,7 @@ func Start(args ProgramArgs) (err error) {
if args.verbose {
fmt.Println("Writing the output Go code...")
}
err = ioutil.WriteFile(outputFilePath, []byte(p.String()), 0644)
err = os.WriteFile(outputFilePath, []byte(p.String()), 0644)
if err != nil {
return fmt.Errorf("writing Go output file failed: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions noarch/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package noarch
import (
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -231,7 +230,7 @@ func Fputs(str *byte, stream *File) int32 {
// abnormally, whether the file is deleted depends on the specific system and
// library implementation.
func Tmpfile() *File {
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
return nil
}
Expand Down Expand Up @@ -396,7 +395,7 @@ func Tmpnam(str *byte) *byte {
// great distinct Go temp file generation (that also checks for existing
// files), but unfortunately creates the file in the process; even if you
// don't intend to use it.
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
if err != nil {
return nil
}
Expand Down
5 changes: 2 additions & 3 deletions preprocessor/preprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -212,7 +211,7 @@ func analyzeFiles(inputFiles, clangFlags []string, verbose bool) (items []entity
// clang -E <file> Run the preprocessor stage.
func getPreprocessSources(inputFiles, clangFlags []string, verbose bool) (out bytes.Buffer, err error) {
// get temp dir
dir, err := ioutil.TempDir("", "c2go-union")
dir, err := os.MkdirTemp("", "c2go-union")
if err != nil {
return
}
Expand All @@ -233,7 +232,7 @@ func getPreprocessSources(inputFiles, clangFlags []string, verbose bool) (out by
}

// write a union file
err = ioutil.WriteFile(unionFileName, []byte(unionBody), 0644)
err = os.WriteFile(unionFileName, []byte(unionBody), 0644)
if err != nil {
return
}
Expand Down

0 comments on commit f296f6e

Please sign in to comment.