diff options
Diffstat (limited to 'bfd/libbfd.c')
-rw-r--r-- | bfd/libbfd.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 2791ca3..b2f83c4 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -860,3 +860,61 @@ warn_deprecated (const char *what, mask |= ~(size_t) func; } } + +/* Helper function for reading uleb128 encoded data. */ + +bfd_vma +read_unsigned_leb128 (bfd *abfd ATTRIBUTE_UNUSED, + char *buf, + unsigned int *bytes_read_ptr) +{ + bfd_vma result; + unsigned int num_read; + int shift; + unsigned char byte; + + result = 0; + shift = 0; + num_read = 0; + do + { + byte = bfd_get_8 (abfd, (bfd_byte *) buf); + buf++; + num_read++; + result |= (((bfd_vma) byte & 0x7f) << shift); + shift += 7; + } + while (byte & 0x80); + *bytes_read_ptr = num_read; + return result; +} + +/* Helper function for reading sleb128 encoded data. */ + +bfd_signed_vma +read_signed_leb128 (bfd *abfd ATTRIBUTE_UNUSED, + char *buf, + unsigned int * bytes_read_ptr) +{ + bfd_vma result; + int shift; + int num_read; + unsigned char byte; + + result = 0; + shift = 0; + num_read = 0; + do + { + byte = bfd_get_8 (abfd, (bfd_byte *) buf); + buf ++; + num_read ++; + result |= (((bfd_vma) byte & 0x7f) << shift); + shift += 7; + } + while (byte & 0x80); + if ((shift < 8 * sizeof (result)) && (byte & 0x40)) + result |= (((bfd_vma) -1) << shift); + *bytes_read_ptr = num_read; + return result; +} |