本文整理汇总了Golang中syscall.Getwd函数的典型用法代码示例。如果您正苦于以下问题:Golang Getwd函数的具体用法?Golang Getwd怎么用?Golang Getwd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Getwd函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CurrentDir
func CurrentDir() string {
dir, err := syscall.Getwd()
if err != nil {
return "."
}
return dir
}
示例2: init
func init() {
wd, err := syscall.Getwd()
if err != nil {
return
}
// The working directory at initialization is the root of the
// app bundle: "/private/.../bundlename.app". That's where we
// keep zoneinfo.zip.
zoneFile = wd + "/zoneinfo.zip"
}
示例3: NewOg
func NewOg(args []string, dir string) *Og {
var err error
if dir == "" || dir == "." {
dir, err = syscall.Getwd()
if err != nil {
log.Fatal("failed to get working directory:", err)
}
}
if _, err := exec.LookPath("go"); err != nil {
log.Fatal("could not find `go` command:", err)
}
return &Og{dir, args}
}
示例4:
}
var sysdir = func() *sysDir {
switch runtime.GOOS {
case "android":
return &sysDir{
"/system/lib",
[]string{
"libmedia.so",
"libpowermanager.so",
},
}
case "darwin":
switch runtime.GOARCH {
case "arm", "arm64":
wd, err := syscall.Getwd()
if err != nil {
wd = err.Error()
}
return &sysDir{
filepath.Join(wd, "..", ".."),
[]string{
"ResourceRules.plist",
"Info.plist",
},
}
}
case "windows":
return &sysDir{
Getenv("SystemRoot") + "\\system32\\drivers\\etc",
[]string{
示例5: Getwd
// Getwd returns a rooted path name corresponding to the
// current directory. If the current directory can be
// reached via multiple paths (due to symbolic links),
// Getwd may return any one of them.
func Getwd() (dir string, err error) {
// If the operating system provides a Getwd call, use it.
if syscall.ImplementsGetwd {
s, e := syscall.Getwd()
if useSyscallwd(e) {
return s, NewSyscallError("getwd", e)
}
}
// Otherwise, we're trying to find our way back to ".".
dot, err := Stat(".")
if err != nil {
return "", err
}
// Clumsy but widespread kludge:
// if $PWD is set and matches ".", use it.
dir = Getenv("PWD")
if len(dir) > 0 && dir[0] == '/' {
d, err := Stat(dir)
if err == nil && SameFile(dot, d) {
return dir, nil
}
}
// Apply same kludge but to cached dir instead of $PWD.
getwdCache.Lock()
dir = getwdCache.dir
getwdCache.Unlock()
if len(dir) > 0 {
d, err := Stat(dir)
if err == nil && SameFile(dot, d) {
return dir, nil
}
}
// Root is a special case because it has no parent
// and ends in a slash.
root, err := Stat("/")
if err != nil {
// Can't stat root - no hope.
return "", err
}
if SameFile(root, dot) {
return "/", nil
}
// General algorithm: find name in parent
// and then find name of parent. Each iteration
// adds /name to the beginning of dir.
dir = ""
for parent := ".."; ; parent = "../" + parent {
if len(parent) >= 1024 { // Sanity check
return "", syscall.ENAMETOOLONG
}
fd, err := Open(parent)
if err != nil {
return "", err
}
for {
names, err := fd.Readdirnames(100)
if err != nil {
fd.Close()
return "", err
}
for _, name := range names {
d, _ := Lstat(parent + "/" + name)
if SameFile(d, dot) {
dir = "/" + name + dir
goto Found
}
}
}
Found:
pd, err := fd.Stat()
if err != nil {
return "", err
}
fd.Close()
if SameFile(pd, root) {
break
}
// Set up for next round.
dot = pd
}
// Save answer as hint to avoid the expensive path next time.
getwdCache.Lock()
getwdCache.dir = dir
getwdCache.Unlock()
return dir, nil
}
示例6:
func ext۰syscall۰Getwd(fn *ssa.Function, args []value) value {
s, err := syscall.Getwd()
return tuple{s, wrapError(err)}
}
示例7:
func ext۰syscall۰Getwd(fr *frame, args []value) value {
s, err := syscall.Getwd()
return tuple{s, wrapError(err)}
}
示例8: Getwd
func Getwd() (wd string, err error) {
return syscall.Getwd()
}