示例#1
0
// Returns a []string with the current search path, in order, and an error, if
// any.
func GetSearchPath() (sp []string, err error) {
	csp := C.PHYSFS_getSearchPath()

	if csp == nil {
		return nil, errors.New(GetLastError())
	}

	i := uintptr(0)
	for {
		p := *(**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(csp)) + i))
		if p == nil {
			break
		}

		sp = append(sp, C.GoString(p))

		i += uintptr(unsafe.Sizeof(csp))
	}

	C.PHYSFS_freeList(unsafe.Pointer(csp))
	return sp, nil
}
示例#2
0
// Returns a []string containing the files and directories in the specified
// directory in your search path, and an error, if any.
func EnumerateFiles(dir string) (list []string, err error) {
	cdir := C.CString(dir)
	defer C.free(unsafe.Pointer(cdir))
	clist := C.PHYSFS_enumerateFiles(cdir)

	if clist == nil {
		return nil, errors.New(GetLastError())
	}

	i := uintptr(0)
	for {
		item := *(**C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(clist)) + i))
		if item == nil {
			break
		}

		list = append(list, C.GoString(item))

		i += uintptr(unsafe.Sizeof(clist))
	}

	C.PHYSFS_freeList(unsafe.Pointer(clist))
	return list, nil
}