2 mmap() a file and writev() back to another file
3 - kernel bug #22452 testcase
6 by D.Buczek - Max Planck Institute for Molecular Genetics Berlin
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <sys/types.h>
33 int main(int argc, char **argv)
36 char *new_file = argv[2];
41 struct iovec iovec[3]=
43 { "aaaaaaaaaa" , 10 },
44 { "bbbbbbbbbb" , 10 },
50 fd=open(file, O_RDONLY);
51 if (fd==-1) {perror("open");exit(1);}
53 base = mmap(NULL,16384,PROT_READ,MAP_SHARED,fd,0);
54 if (base == (void *)-1) { perror("mmap");exit(1); }
58 fd_new=open(new_file,O_RDWR|O_CREAT,0666);
59 if (fd_new==-1) {perror("creat");exit(1);}
61 iovec[2].iov_base=(char *)base;
62 i=writev(fd_new,iovec,sizeof(iovec)/sizeof(*iovec));
63 if (i==-1) {perror("writev");exit(1);}