/* * Main program */ int main(int argc, char **argv) { int fd; process_options(argc, argv); /* Open the input file */ if ((fd = open(img, O_RDONLY)) == -1) { perror("open input file"); exit(1); } // get image length imglen = lseek(fd, 0, SEEK_END); lseek (fd, 0, SEEK_SET); data = malloc (imglen); if (!data) { perror("out of memory"); close (fd); exit(1); } if (datsize && oobsize) { int idx = 0; long len = imglen; uint8_t oob[oobsize]; printf ("Peeling data out of combined data/oob image\n"); while (len) { // read image data read (fd, &data[idx], datsize); read (fd, oob, oobsize); idx += datsize; imglen -= oobsize; len -= datsize + oobsize; } } else { // read image data read (fd, data, imglen); } // Close the input file close(fd); if (dumpcontent) do_dumpcontent (); if (convertendian) do_endianconvert (); // free memory free (data); // Return happy exit (0); }
/* * Main program */ int main(int argc, char **argv) { int fd; process_options(argc, argv); /* Open the input file */ if ((fd = open(img, O_RDONLY)) == -1) { perror("open input file"); exit(1); } // get image length imglen = lseek(fd, 0, SEEK_END); lseek (fd, 0, SEEK_SET); data = malloc (imglen); if (!data) { perror("out of memory"); close (fd); exit(1); } // read image data read (fd, data, imglen); // Close the input file close(fd); if (dumpcontent) do_dumpcontent (); if (convertendian) do_endianconvert (); // free memory free (data); // Return happy exit (0); }