From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Wagner Date: Wed, 23 Nov 2011 21:28:15 +0100 Subject: [U-Boot] [PATCH 6/9] mkenvimage: Use mmap() when reading from a regular file In-Reply-To: <1322080098-3151-1-git-send-email-david.wagner@free-electrons.com> References: <1322080098-3151-1-git-send-email-david.wagner@free-electrons.com> Message-ID: <1322080098-3151-7-git-send-email-david.wagner@free-electrons.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Signed-off-by: David Wagner --- tools/mkenvimage.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c index 86a4e05..74b296e 100644 --- a/tools/mkenvimage.c +++ b/tools/mkenvimage.c @@ -35,6 +35,7 @@ #include "compiler.h" #include #include +#include #include "u-boot/crc.h" @@ -190,14 +191,16 @@ int main(int argc, char **argv) } filesize = txt_file_stat.st_size; - /* Read the raw input file and transform it */ - filebuf = malloc(sizeof(*envptr) * filesize); - ret = read(txt_fd, filebuf, sizeof(*envptr) * filesize); - if (ret != sizeof(*envptr) * filesize) { - fprintf(stderr, "Can't read the whole input file\n"); + + filebuf = mmap(NULL, sizeof(*envptr) * filesize, PROT_READ, + MAP_PRIVATE, txt_fd, 0); + ret = close(txt_fd); + if (filebuf == MAP_FAILED) { + fprintf(stderr, "mmap (%d bytes) failed: %s\n", + sizeof(*envptr) * filesize, + strerror(errno)); return EXIT_FAILURE; } - ret = close(txt_fd); } /* The +1 is for the additionnal ending \0. See below. */ if (filesize + 1 > envsize) { -- 1.7.7.3