- fprintf(stderr, "Cannot open %s\n", filename);
- return -1;
- }
- map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);
- close(ifd);
- if (-1 == (int)(long)map) {
- fprintf(stderr, "Cannot mmap %s\n", filename);
- return -1;
+ if (-1 == (int)(long)map) {
+ fprintf(stderr, "cannot mmap %s\n", filename);
+ return -1;
+ }
+ ofd = open(dest_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
+ status = ((ofd < 0) ||
+ (write(ofd, map, st.st_size) != st.st_size));
+ munmap(map, st.st_size);
+ close(ofd);
+ if (status)
+ fprintf(stderr, "cannot write %s\n", dest_filename);
+ else
+ pull_say("copy %s\n", hex);
+ return status;