当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.Getwd函数代码示例

本文整理汇总了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
}
开发者ID:kobo,项目名称:groovyserv,代码行数:7,代码来源:platform.go

示例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"
}
开发者ID:2thetop,项目名称:go,代码行数:11,代码来源:zoneinfo_ios.go

示例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}
}
开发者ID:jmptrader,项目名称:og,代码行数:13,代码来源:og.go

示例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{
开发者ID:duhaibo0404,项目名称:go-1,代码行数:31,代码来源:os_test.go

示例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
}
开发者ID:h8liu,项目名称:golang,代码行数:99,代码来源:getwd.go

示例6:

func ext۰syscall۰Getwd(fn *ssa.Function, args []value) value {
	s, err := syscall.Getwd()
	return tuple{s, wrapError(err)}
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:4,代码来源:external.go

示例7:

func ext۰syscall۰Getwd(fr *frame, args []value) value {
	s, err := syscall.Getwd()
	return tuple{s, wrapError(err)}
}
开发者ID:binaryedge,项目名称:40fy-client,代码行数:4,代码来源:external.go

示例8: Getwd

func Getwd() (wd string, err error) {
	return syscall.Getwd()
}
开发者ID:Chengyumeng,项目名称:sys,代码行数:3,代码来源:pwd_go15_plan9.go


注:本文中的syscall.Getwd函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。