diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-03-17 13:53:14 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-03-17 13:53:14 +0900 |
| commit | 0cb1007daaea2b8f6b28bff72aa5d08aea981ea9 (patch) | |
| tree | 9950dcdaaaf67bdd937c83855dd6401e35012d6e /ldd/ldd.go | |
| parent | e292031624b7fe57d508476828e51ca66d520bcb (diff) | |
ldd: remove deprecated API
Closes #25.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ldd/ldd.go')
| -rw-r--r-- | ldd/ldd.go | 63 |
1 files changed, 36 insertions, 27 deletions
@@ -1,9 +1,9 @@ -// Package ldd provides a robust parser for ldd(1) output, and a convenience function -// for running ldd(1) in a strict sandbox. +// Package ldd provides a robust parser for ldd(1) output, and a convenience +// function for running ldd(1) in a strict sandbox. // -// Note: despite the additional hardening, great care must be taken when using ldd(1). -// As a general rule, you must never run ldd(1) against a file that you do not wish to -// execute within the same context. +// Note: despite the additional hardening, great care must be taken when using +// ldd(1). As a general rule, you must never run ldd(1) against a file that you +// do not wish to execute within the same context. package ldd import ( @@ -27,8 +27,8 @@ var ( ErrBadLocationFormat = errors.New("bad location format") ) -// EntryUnexpectedSegmentsError is returned when encountering -// a line containing unexpected number of segments. +// EntryUnexpectedSegmentsError is returned when encountering a line containing +// unexpected number of segments. type EntryUnexpectedSegmentsError string func (e EntryUnexpectedSegmentsError) Error() string { @@ -51,26 +51,31 @@ const ( // entrySegmentIndexPath is the index of the segment holding [Entry.Path], // present only for a line describing a fully populated [Entry]. entrySegmentIndexPath = 2 - // entrySegmentIndexSeparator is the index of the segment containing the magic bytes entrySegmentFullSeparator, - // present only for a line describing a fully populated [Entry]. + // entrySegmentIndexSeparator is the index of the segment containing the + // magic bytes entrySegmentFullSeparator, present only for a line describing + // a fully populated [Entry]. entrySegmentIndexSeparator = 1 - // entrySegmentIndexLocation is the index of the segment holding [Entry.Location] - // for a line describing a fully populated [Entry]. + // entrySegmentIndexLocation is the index of the segment holding + // [Entry.Location] for a line describing a fully populated [Entry]. entrySegmentIndexLocation = 3 - // entrySegmentIndexLocationShort is the index of the segment holding [Entry.Location] - // for a line describing only [Entry.Name]. + // entrySegmentIndexLocationShort is the index of the segment holding + // [Entry.Location] for a line describing only [Entry.Name]. entrySegmentIndexLocationShort = 1 // entrySegmentSep is the byte separating segments in an [Entry] line. entrySegmentSep = ' ' - // entrySegmentFullSeparator is the exact contents of the segment at index entrySegmentIndexSeparator. + // entrySegmentFullSeparator is the exact contents of the segment at index + // entrySegmentIndexSeparator. entrySegmentFullSeparator = "=>" - // entrySegmentLocationLengthMin is the minimum possible length of a segment corresponding to [Entry.Location]. + // entrySegmentLocationLengthMin is the minimum possible length of a segment + // corresponding to [Entry.Location]. entrySegmentLocationLengthMin = 4 - // entrySegmentLocationPrefix are magic bytes prefixing a segment corresponding to [Entry.Location]. + // entrySegmentLocationPrefix are magic bytes prefixing a segment + // corresponding to [Entry.Location]. entrySegmentLocationPrefix = "(0x" - // entrySegmentLocationSuffix is the magic byte suffixing a segment corresponding to [Entry.Location]. + // entrySegmentLocationSuffix is the magic byte suffixing a segment + // corresponding to [Entry.Location]. entrySegmentLocationSuffix = ')' ) @@ -144,7 +149,9 @@ func (e *Entry) String() string { if e.Path != nil { buf.WriteString(entrySegmentFullSeparator + " " + e.Path.String() + " ") } - buf.WriteString(entrySegmentLocationPrefix + strconv.FormatUint(e.Location, 16) + string(entrySegmentLocationSuffix)) + buf.WriteString(entrySegmentLocationPrefix + + strconv.FormatUint(e.Location, 16) + + string(entrySegmentLocationSuffix)) return buf.String() } @@ -180,12 +187,12 @@ type Decoder struct { // NewDecoder returns a new decoder that reads from r. // -// The decoder introduces its own buffering and may read -// data from r beyond the [Entry] values requested. +// The decoder introduces its own buffering and may read data from r beyond the +// [Entry] values requested. func NewDecoder(r io.Reader) *Decoder { return &Decoder{s: bufio.NewScanner(r)} } -// Scan advances the [Decoder] to the next [Entry] and -// stores the result in the value pointed to by v. +// Scan advances the [Decoder] to the next [Entry] and stores the result in the +// value pointed to by v. func (d *Decoder) Scan(v *Entry) bool { if d.s == nil || d.err != nil || d.depleted { return false @@ -215,8 +222,8 @@ func (d *Decoder) Scan(v *Entry) bool { return d.err == nil } -// Err returns the first non-EOF error that was encountered -// by the underlying [bufio.Scanner] or [Entry]. +// Err returns the first non-EOF error that was encountered by the underlying +// [bufio.Scanner] or [Entry]. func (d *Decoder) Err() error { if d.err != nil || d.s == nil { return d.err @@ -224,8 +231,8 @@ func (d *Decoder) Err() error { return d.s.Err() } -// Decode reads from the input stream until there are no more entries -// and returns the results in a slice. +// Decode reads from the input stream until there are no more entries and +// returns the results in a slice. func (d *Decoder) Decode() ([]*Entry, error) { var entries []*Entry @@ -238,4 +245,6 @@ func (d *Decoder) Decode() ([]*Entry, error) { } // Parse returns a slice of addresses to [Entry] decoded from p. -func Parse(p []byte) ([]*Entry, error) { return NewDecoder(bytes.NewReader(p)).Decode() } +func Parse(p []byte) ([]*Entry, error) { + return NewDecoder(bytes.NewReader(p)).Decode() +} |
