aboutsummaryrefslogtreecommitdiffhomepage
path: root/ldd
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-03-16 01:20:09 +0900
committerOphestra <cat@gensokyo.uk>2025-03-16 01:20:09 +0900
commit273d97af8502059193ccb6a188422f9d22eaf106 (patch)
treed26ae85bbdd32d15c8581627923c607a261370e3 /ldd
parent891316d9240fc5cf451ad88f92e82f82b1751ab8 (diff)
ldd: lib paths resolve function
This is what always happens right after a ldd call, so implement it here. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd')
-rw-r--r--ldd/path.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/ldd/path.go b/ldd/path.go
new file mode 100644
index 00000000..4e41ce74
--- /dev/null
+++ b/ldd/path.go
@@ -0,0 +1,21 @@
+package ldd
+
+import (
+ "path"
+ "slices"
+)
+
+// Path returns a deterministic, deduplicated slice of absolute directory paths in entries.
+func Path(entries []*Entry) []string {
+ p := make([]string, 0, len(entries)*2)
+ for _, entry := range entries {
+ if path.IsAbs(entry.Path) {
+ p = append(p, path.Dir(entry.Path))
+ }
+ if path.IsAbs(entry.Name) {
+ p = append(p, path.Dir(entry.Name))
+ }
+ }
+ slices.Sort(p)
+ return slices.Compact(p)
+}