alpm.go 669 B

1234567891011121314151617181920212223242526272829
  1. // alpm.go - Implements exported libalpm functions.
  2. //
  3. // Copyright (c) 2013 The go-alpm Authors
  4. //
  5. // MIT Licensed. See LICENSE for details.
  6. package alpm
  7. // #cgo LDFLAGS: -lalpm
  8. // #include <alpm.h>
  9. import "C"
  10. import "unsafe"
  11. // Version returns libalpm version string.
  12. func Version() string {
  13. return C.GoString(C.alpm_version())
  14. }
  15. // VerCmp performs version comparison according to Pacman conventions. Return
  16. // value is <0 if and only if v1 is older than v2.
  17. func VerCmp(v1, v2 string) int {
  18. c1 := C.CString(v1)
  19. c2 := C.CString(v2)
  20. defer C.free(unsafe.Pointer(c1))
  21. defer C.free(unsafe.Pointer(c2))
  22. result := C.alpm_pkg_vercmp(c1, c2)
  23. return int(result)
  24. }