1 // SPDX-License-Identifier: GPL-2.0+
4 * by D.Buczek - Max Planck Institute for Molecular Genetics Berlin
6 * mmap() a file and writev() back to another file
7 * - kernel bug #22452 testcase
10 #include <sys/types.h>
20 int main(int argc, char **argv)
23 char *new_file = argv[2];
28 struct iovec iovec[3]=
30 { "aaaaaaaaaa" , 10 },
31 { "bbbbbbbbbb" , 10 },
37 fd=open(file, O_RDONLY);
38 if (fd==-1) {perror("open");exit(1);}
40 base = mmap(NULL,16384,PROT_READ,MAP_SHARED,fd,0);
41 if (base == MAP_FAILED) { perror("mmap");exit(1); }
45 fd_new=open(new_file,O_RDWR|O_CREAT,0666);
46 if (fd_new==-1) {perror("creat");exit(1);}
48 iovec[2].iov_base=(char *)base;
49 i=writev(fd_new,iovec,sizeof(iovec)/sizeof(*iovec));
50 if (i==-1) {perror("writev");exit(1);}