-
- filesize = txt_file_stat.st_size;
-
- filebuf = mmap(NULL, sizeof(*envptr) * filesize, PROT_READ,
- MAP_PRIVATE, txt_fd, 0);
- if (filebuf == MAP_FAILED) {
- fprintf(stderr, "mmap (%ld bytes) failed: %s\n",
- sizeof(*envptr) * filesize,
- strerror(errno));
- fprintf(stderr, "Falling back to read()\n");
-
- 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 (%ld bytes): %s\n",
- sizeof(*envptr) * filesize,
- strerror(errno));
-
- return EXIT_FAILURE;
- }
+ readbytes = read(txt_fd, filebuf + filesize, CHUNK_SIZE);
+ if (readbytes < 0) {
+ fprintf(stderr, "Error while reading: %s\n",
+ strerror(errno));
+ return EXIT_FAILURE;