From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 464F4138A1A for ; Tue, 6 Jan 2015 21:34:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 3540AE07EA; Tue, 6 Jan 2015 21:34:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E1B91E07EA for ; Tue, 6 Jan 2015 21:34:37 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9835B340740 for ; Tue, 6 Jan 2015 21:34:36 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4398AF042 for ; Tue, 6 Jan 2015 21:34:35 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1420580138.cb2af57d4d0230dbb38f314c24f4118f9dbd679c.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/elf-abi/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/elf-abi/elf-abi.c X-VCS-Directories: misc/elf-abi/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: cb2af57d4d0230dbb38f314c24f4118f9dbd679c X-VCS-Branch: master Date: Tue, 6 Jan 2015 21:34:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 870f4552-9ae7-414c-990f-69a8b9021eb0 X-Archives-Hash: dacddccaa3e932e7227785db1ca558e8 commit: cb2af57d4d0230dbb38f314c24f4118f9dbd679c Author: Anthony G. Basile gentoo org> AuthorDate: Tue Jan 6 21:35:38 2015 +0000 Commit: Anthony G. Basile gentoo 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);