[U-Boot] [PATCHv2 6/8] mkenvimage: Use mmap() when reading from a regular file
Mike Frysinger
vapier at gentoo.org
Sun Jan 8 07:51:33 CET 2012
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: <http://lists.denx.de/pipermail/u-boot/attachments/20120108/88943d68/attachment.pgp>
More information about the U-Boot
mailing list