From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Frysinger Date: Sun, 8 Jan 2012 01:51:33 -0500 Subject: [U-Boot] [PATCHv2 6/8] mkenvimage: Use mmap() when reading from a regular file In-Reply-To: <1325789099-9260-6-git-send-email-david.wagner@free-electrons.com> References: <20120105162831.E91BE1FD3DA@gemini.denx.de> <1325789099-9260-1-git-send-email-david.wagner@free-electrons.com> <1325789099-9260-6-git-send-email-david.wagner@free-electrons.com> Message-ID: <201201080151.33954.vapier@gentoo.org> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thursday 05 January 2012 13:44:57 David Wagner wrote: > --- a/tools/mkenvimage.c > +++ b/tools/mkenvimage.c > > 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 (%ld bytes) failed: %s\n", > + sizeof(*envptr) * filesize, > + strerror(errno)); > return EXIT_FAILURE; > } > - ret = close(txt_fd); seems like the mmap() failure shouldn't be fatal. just have it fallback to the normal read()/write() logic. -mike -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: This is a digitally signed message part. URL: