yay/vendor/github.com/Jguer/go-alpm/alpm.go

56 lines
1.0 KiB
Go
Raw Normal View History

2017-07-14 19:03:54 +02:00
// alpm.go - Implements exported libalpm functions.
//
// Copyright (c) 2013 The go-alpm Authors
//
// MIT Licensed. See LICENSE for details.
package alpm
// #cgo LDFLAGS: -lalpm
// #include <alpm.h>
import "C"
import "unsafe"
2019-02-04 17:56:02 +01:00
// Init initializes alpm handle
func Initialize(root, dbpath string) (*Handle, error) {
cRoot := C.CString(root)
cDBPath := C.CString(dbpath)
var cErr C.alpm_errno_t
h := C.alpm_initialize(cRoot, cDBPath, &cErr)
defer C.free(unsafe.Pointer(cRoot))
defer C.free(unsafe.Pointer(cDBPath))
if cErr != 0 {
return nil, Error(cErr)
}
return &Handle{h}, nil
}
// Release releases the alpm handle
func (h *Handle) Release() error {
if er := C.alpm_release(h.ptr); er != 0 {
return Error(er)
}
h.ptr = nil
return nil
}
// LastError gets the last pm_error
func (h *Handle) LastError() error {
if h.ptr != nil {
cErr := C.alpm_errno(h.ptr)
if cErr != 0 {
return Error(cErr)
}
}
return nil
}
2017-07-14 19:03:54 +02:00
// Version returns libalpm version string.
func Version() string {
return C.GoString(C.alpm_version())
}