forked from gen2brain/heic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpurego_unix.go
More file actions
50 lines (38 loc) · 798 Bytes
/
purego_unix.go
File metadata and controls
50 lines (38 loc) · 798 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//go:build linux && !android && !darwin && !(nodynamic || arm || 386 || mips || mipsle)
package heic
import (
"debug/elf"
"fmt"
"os"
"runtime"
"github.com/ebitengine/purego"
)
const (
libname = "libheif.so"
)
func loadLibrary() (uintptr, error) {
if runtime.GOOS == "linux" && !isDynamicBinary() {
return 0, fmt.Errorf("not a dynamic binary")
}
handle, err := purego.Dlopen(libname, purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
return 0, fmt.Errorf("cannot load library: %w", err)
}
return handle, nil
}
func isDynamicBinary() bool {
fileName, err := os.Executable()
if err != nil {
panic(err)
}
fl, err := elf.Open(fileName)
if err != nil {
panic(err)
}
defer fl.Close()
_, err = fl.DynamicSymbols()
if err == nil {
return true
}
return false
}