From dcf893f99cdcead3d82e987953341caa030b30f9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 24 Sep 2017 10:04:02 +0200 Subject: pkg/osutil: windows port --- pkg/osutil/osutil.go | 28 ++++++++++++++++++++++++++++ pkg/osutil/osutil_fuchsia.go | 8 -------- pkg/osutil/osutil_unix.go | 20 -------------------- pkg/osutil/osutil_windows.go | 7 +++++++ 4 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 pkg/osutil/osutil_windows.go (limited to 'pkg/osutil') diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 79cd455c2..d98e91e19 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "time" ) @@ -145,3 +146,30 @@ func ListDir(dir string) ([]string, error) { defer f.Close() return f.Readdirnames(-1) } + +var wd string + +func init() { + if runtime.GOOS == "fuchsia" { + return + } + var err error + wd, err = os.Getwd() + if err != nil { + panic(fmt.Sprintf("failed to get wd: %v", err)) + } +} + +func Abs(path string) string { + if runtime.GOOS == "fuchsia" { + // Getwd/Abs are not supported on fuchsia. Let's hope for best. + return path + } + if wd1, err := os.Getwd(); err == nil && wd1 != wd { + panic("don't mess with wd in a concurrent program") + } + if path == "" || filepath.IsAbs(path) { + return path + } + return filepath.Join(wd, path) +} diff --git a/pkg/osutil/osutil_fuchsia.go b/pkg/osutil/osutil_fuchsia.go index 75cdad843..db7b041d6 100644 --- a/pkg/osutil/osutil_fuchsia.go +++ b/pkg/osutil/osutil_fuchsia.go @@ -7,11 +7,3 @@ package osutil func HandleInterrupts(shutdown chan struct{}) { } - -func Abs(path string) string { - // Getwd is not implemented. Let's hope for best. - if path == "" { - return "" - } - return "./" + path -} diff --git a/pkg/osutil/osutil_unix.go b/pkg/osutil/osutil_unix.go index 27482b99a..01eabc15b 100644 --- a/pkg/osutil/osutil_unix.go +++ b/pkg/osutil/osutil_unix.go @@ -90,23 +90,3 @@ func LongPipe() (io.ReadCloser, io.WriteCloser, error) { prolongPipe(r, w) return r, w, err } - -var wd string - -func init() { - var err error - wd, err = os.Getwd() - if err != nil { - panic(fmt.Sprintf("failed to get wd: %v", err)) - } -} - -func Abs(path string) string { - if wd1, err := os.Getwd(); err == nil && wd1 != wd { - panic("don't mess with wd in a concurrent program") - } - if path == "" || filepath.IsAbs(path) { - return path - } - return filepath.Join(wd, path) -} diff --git a/pkg/osutil/osutil_windows.go b/pkg/osutil/osutil_windows.go new file mode 100644 index 000000000..861ae8fb3 --- /dev/null +++ b/pkg/osutil/osutil_windows.go @@ -0,0 +1,7 @@ +// Copyright 2017 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package osutil + +func HandleInterrupts(shutdown chan struct{}) { +} -- cgit mrf-deployment