exit(1);
}
- if (stat(infname, &statbuf) < 0) {
- fprintf(stderr,
- "could not find input file. (errno = %d)\n", errno);
- exit(1);
- }
-
- filebuf = malloc(statbuf.st_size + padsz);
- if (!filebuf) {
- fprintf(stderr, "buffer allocation failed\n");
- exit(1);
- }
-
ifd = open(infname, O_RDONLY);
if (ifd < 0) {
fprintf(stderr,
exit(1);
}
+ if (fstat(ifd, &statbuf) < 0) {
+ fprintf(stderr,
+ "could not fstat input file. (errno = %d)\n", errno);
+ exit(1);
+ }
+
+ filebuf = malloc(statbuf.st_size + padsz);
+ if (!filebuf) {
+ fprintf(stderr, "buffer allocation failed\n");
+ exit(1);
+ }
+
rsz = read(ifd, filebuf, sizeof(*imgh));
if (rsz != sizeof(*imgh)) {
fprintf(stderr,