aboutsummaryrefslogtreecommitdiffhomepage
path: root/ldd/ldd.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-14 21:38:35 +0900
committerOphestra <cat@gensokyo.uk>2025-11-14 21:38:35 +0900
commit42759e7a9f4e6c45d2e043a404e444160e6cddba (patch)
tree0485fd954967766cc97f1c97cbbc44814752be3b /ldd/ldd.go
parent8e2d2c8246409dca96cee8589c0d841ef878d802 (diff)
ldd: create musl entry representation
This mostly helps with debugging. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd/ldd.go')
-rw-r--r--ldd/ldd.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/ldd/ldd.go b/ldd/ldd.go
index 7b88e698..9c892d7a 100644
--- a/ldd/ldd.go
+++ b/ldd/ldd.go
@@ -13,6 +13,7 @@ import (
"fmt"
"io"
"strconv"
+ "strings"
"hakurei.app/container/check"
)
@@ -117,6 +118,37 @@ func (e *Entry) UnmarshalText(data []byte) error {
return e.decodeLocationSegment(segments[iL])
}
+// String returns the musl ldd(1) representation of [Entry].
+func (e *Entry) String() string {
+ // nameInvalid is used for a zero-length e.Name
+ const nameInvalid = "invalid"
+
+ var buf strings.Builder
+
+ // libzstd.so.1 => /usr/lib/libzstd.so.1 (0x7ff71bfd2000)
+ l := len(e.Name) + 1
+ if e.Name == "" {
+ l += len(nameInvalid)
+ }
+ if e.Path != nil {
+ l += len(entrySegmentFullSeparator) + 1 + len(e.Path.String()) + 1
+ }
+ l += len(entrySegmentLocationPrefix) + 1<<4 + 1
+ buf.Grow(l)
+
+ if e.Name != "" {
+ buf.WriteString(e.Name + " ")
+ } else {
+ buf.WriteString(nameInvalid + " ")
+ }
+ if e.Path != nil {
+ buf.WriteString(entrySegmentFullSeparator + " " + e.Path.String() + " ")
+ }
+ buf.WriteString(entrySegmentLocationPrefix + strconv.FormatUint(e.Location, 16) + string(entrySegmentLocationSuffix))
+
+ return buf.String()
+}
+
// Path returns a deduplicated slice of absolute directory paths in entries.
func Path(entries []*Entry) []*check.Absolute {
p := make([]*check.Absolute, 0, len(entries)*2)