From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:master commit in: misc/elf-abi/
Date: Tue, 6 Jan 2015 21:34:35 +0000 (UTC) [thread overview]
Message-ID: <1420580138.cb2af57d4d0230dbb38f314c24f4118f9dbd679c.blueness@gentoo> (raw)
commit: cb2af57d4d0230dbb38f314c24f4118f9dbd679c
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 6 21:35:38 2015 +0000
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Tue Jan 6 21:35:38 2015 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=cb2af57d
misc/elf-abi: fixup read_endian()
---
misc/elf-abi/elf-abi.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/misc/elf-abi/elf-abi.c b/misc/elf-abi/elf-abi.c
index f4408cb..3be6aae 100644
--- a/misc/elf-abi/elf-abi.c
+++ b/misc/elf-abi/elf-abi.c
@@ -211,22 +211,23 @@ get_abi(uint16_t e_machine, int width, uint32_t e_flags)
/* Elf object on a big endian (eg. if you are cross compiling), then you get the wrong */
/* byte order. If howerver, you read it natively, you get it right. We'll wrap read() */
/* with our own version which reads one byte at a time and corrects this. */
-ssize_t
-read_endian(int fd, void *buf, size_t count, int endian)
+uint64_t
+read_endian(int fd, size_t count, int endian)
{
ssize_t i;
uint8_t data;
+ uint64_t value = 0;
for(i = 0; i < count; i++) {
if (read(fd, &data, 1) == -1)
errx(1, "read() ei_class failed");
if (endian)
- ((uint8_t *)buf)[count-i-1] = data;
+ value += data << 8 * (count-i-1);
else
- ((uint8_t *)buf)[i] = data;
+ value += data << 8 * i;
}
- return count;
+ return value;
}
@@ -296,11 +297,11 @@ main(int argc, char* argv[])
/* What is the abi? */
if (lseek(fd, e_machine_offset, SEEK_SET) == -1)
errx(1, "lseek() e_machine failed");
- read_endian(fd, &e_machine, 2, endian);
+ e_machine = (uint16_t)read_endian(fd, 2, endian);
if (lseek(fd, e_flags_offset, SEEK_SET) == -1)
errx(1, "lseek() e_flags failed");
- read_endian(fd, &e_flags, 4, endian);
+ e_flags = (uint32_t)read_endian(fd, 4, endian);
abi = get_abi(e_machine, width, e_flags);
printf("%s\n", abi);
next reply other threads:[~2015-01-06 21:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-06 21:34 Anthony G. Basile [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-01-06 21:43 [gentoo-commits] proj/elfix:master commit in: misc/elf-abi/ Anthony G. Basile
2015-01-06 20:47 Anthony G. Basile
2015-01-06 18:22 Anthony G. Basile
2015-01-06 17:26 Anthony G. Basile
2015-01-06 15:13 Anthony G. Basile
2015-01-05 16:26 Anthony G. Basile
2015-01-05 16:23 Anthony G. Basile
2015-01-03 23:53 Anthony G. Basile
2015-01-03 23:49 Anthony G. Basile
2015-01-03 23:19 Anthony G. Basile
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420580138.cb2af57d4d0230dbb38f314c24f4118f9dbd679c.blueness@gentoo \
--to=blueness@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox