-
Notifications
You must be signed in to change notification settings - Fork 11
/
init_unix.go
31 lines (27 loc) · 687 Bytes
/
init_unix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build unix && !cmd_go_bootstrap
package openssl
// #cgo LDFLAGS: -ldl -pthread
// #include <stdlib.h>
// #include <dlfcn.h>
import "C"
import (
"errors"
"unsafe"
)
func dlopen(file string) (handle unsafe.Pointer, err error) {
cv := C.CString(file)
defer C.free(unsafe.Pointer(cv))
handle = C.dlopen(cv, C.RTLD_LAZY|C.RTLD_LOCAL)
if handle == nil {
errstr := C.GoString(C.dlerror())
return nil, errors.New("openssl: can't load " + file + ": " + errstr)
}
return handle, nil
}
func dlclose(handle unsafe.Pointer) error {
if C.dlclose(handle) != 0 {
errstr := C.GoString(C.dlerror())
return errors.New("openssl: can't close libcrypto: " + errstr)
}
return nil
}