Exemplo n.º 1
0
func getResourceDir() string {
	bufSize := C.uint32_t(0)
	C._NSGetExecutablePath(nil, &bufSize)
	buf := make([]C.char, bufSize)
	C._NSGetExecutablePath(&buf[0], &bufSize)
	return path.Dir(C.GoString(&buf[0])) + "/../Resources/"
}
Exemplo n.º 2
0
func binPath() string {
	var n C.uint32_t
	C._NSGetExecutablePath(nil, &n)
	b := make([]byte, int(n))
	C._NSGetExecutablePath((*C.char)(unsafe.Pointer(&b[0])), &n)
	return string(b[:n-1])
}
Exemplo n.º 3
0
func Path() (string, error) {
	var buflen C.uint32_t = 1024
	buf := make([]C.char, buflen)

	ret := C._NSGetExecutablePath(&buf[0], &buflen)
	if ret == -1 {
		buf = make([]C.char, buflen)
		C._NSGetExecutablePath(&buf[0], &buflen)
	}
	return C.GoString(&buf[0]), nil
}
Exemplo n.º 4
0
func GetExecutableDir() string {
	var path []C.char = make([]C.char, 1024)
	var size C.uint32_t = 1024
	if C._NSGetExecutablePath(&path[0], &size) == 0 {
		return filepath.Dir(C.GoString(&path[0]))
	}
	return "."
}
Exemplo n.º 5
0
// GetExecutablePath returns the absolute path to the currently running
// executable.  It is used internally by the godaemon package, and exported
// publicly because it's useful outside of the package too.
func GetExecutablePath() (string, error) {
	PATH_MAX := 1024 // From <sys/syslimits.h>
	exePath := make([]byte, PATH_MAX)
	exeLen := C.uint32_t(len(exePath))

	status, err := C._NSGetExecutablePath((*C.char)(unsafe.Pointer(&exePath[0])), &exeLen)

	if err != nil {
		return "", fmt.Errorf("_NSGetExecutablePath: %v", err)
	}

	// Not sure why this might happen with err being nil, but...
	if status != 0 {
		return "", fmt.Errorf("_NSGetExecutablePath returned %d", status)
	}

	// Convert from null-padded []byte to a clean string. (Can't simply cast!)
	exePathStringLen := bytes.Index(exePath, []byte{0})
	exePathString := string(exePath[:exePathStringLen])

	return filepath.Clean(exePathString), nil
}