aboutsummaryrefslogtreecommitdiffhomepage
path: root/ldd/ldd.go
diff options
context:
space:
mode:
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)