From 1f580dac3d82075b93cc18044501fd01024d5f9a Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 23 Dec 2015 13:59:29 +0100 Subject: fileutil: new package Move some file utilities into a separate package. --- csource/csource.go | 15 --------------- csource/csource_test.go | 3 ++- 2 files changed, 2 insertions(+), 16 deletions(-) (limited to 'csource') diff --git a/csource/csource.go b/csource/csource.go index 03ce4b84c..5caa74af5 100644 --- a/csource/csource.go +++ b/csource/csource.go @@ -199,21 +199,6 @@ loop: return calls, n } -// WriteTempFile writes data to a temp file and returns its name. -func WriteTempFile(data []byte) (string, error) { - f, err := ioutil.TempFile("", "syz-prog") - if err != nil { - return "", fmt.Errorf("failed to create a temp file: %v", err) - } - if _, err := f.Write(data); err != nil { - f.Close() - os.Remove(f.Name()) - return "", fmt.Errorf("failed to write temp file: %v", err) - } - f.Close() - return f.Name(), nil -} - // Build builds a C/C++ program from source file src // and returns name of the resulting binary. func Build(src string) (string, error) { diff --git a/csource/csource_test.go b/csource/csource_test.go index b2fbda6dc..388ab0e1a 100644 --- a/csource/csource_test.go +++ b/csource/csource_test.go @@ -9,6 +9,7 @@ import ( "testing" "time" + "github.com/google/syzkaller/fileutil" "github.com/google/syzkaller/prog" ) @@ -40,7 +41,7 @@ func Test(t *testing.T) { func testOne(t *testing.T, p *prog.Prog, opts Options) { src := Write(p, opts) - srcf, err := WriteTempFile(src) + srcf, err := fileutil.WriteTempFile(src) if err != nil { t.Fatalf("%v", err) } -- cgit mrf-deployment