diff --git a/mmapcp b/mmapcp new file mode 100644 index 0000000..281795a Binary files /dev/null and b/mmapcp differ diff --git a/mmapcp.cc b/mmapcp.cc index ce0e292..ca9d937 100644 --- a/mmapcp.cc +++ b/mmapcp.cc @@ -8,37 +8,52 @@ int main(int argc, char *argv[]) { - int s, d; - struct stat st; - void *sp, *dp; - s = open(argv[1], O_RDONLY); - if (s == -1) { - perror("open source"); - exit(1); - } - d = open(argv[2], O_RDWR | O_CREAT | O_TRUNC, 0644); - if (d == -1) { - perror("open destintation"); - exit(1); - } - if (fstat(s, &st)) { - perror("stat source"); - exit(1); - } - if (ftruncate(d, st.st_size)) { - perror("truncate destination"); - exit(1); - } - sp = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, s, 0); - if (sp == MAP_FAILED) { - perror("map source"); - exit(1); - } - dp = mmap(NULL, st.st_size, PROT_WRITE | PROT_READ, MAP_SHARED, d, 0); - if (dp == MAP_FAILED) { - perror("map destintation"); - exit(1); - } - memcpy(dp, sp, st.st_size); - return 0; + int s, s2, d; + struct stat st; + struct stat s2t; + void *sp, *s2p, *dp; + s = open(argv[1], O_RDONLY); + if (s == -1) { + perror("open source"); + exit(1); + } + s2 = open(argv[2], O_RDONLY); + if (s2 == -1) { + perror("open source2"); + exit(1); + } + d = open(argv[3], O_RDWR | O_CREAT | O_TRUNC, 0644); + if (d == -1) { + perror("open destination"); + exit(1); + } + if (fstat(s, &st)) { + perror("stat source"); + exit(1); + } + if (fstat(s2, &s2t)) { + perror("stat source2"); + exit(1); + } + if (ftruncate(d, st.st_size + s2t.st_size)) { + perror("truncate destination"); + exit(1); + } + sp = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, s, 0); + if (sp == MAP_FAILED) { + perror("map source"); + exit(1); + } + s2p = mmap(NULL, s2t.st_size, PROT_READ, MAP_SHARED, s2, 0); + if (s2p == MAP_FAILED) { + perror("map source2"); + exit(1); + } + dp = mmap(NULL, st.st_size + s2t.st_size, PROT_WRITE | PROT_READ, MAP_SHARED, d, 0); + if (dp == MAP_FAILED) { + perror("map destination"); + exit(1); + } + memcpy(dp, sp, st.st_size); + return 0; } diff --git a/mymom b/mymom new file mode 100644 index 0000000..b0b9918 --- /dev/null +++ b/mymom @@ -0,0 +1 @@ +mymom \ No newline at end of file diff --git a/out b/out new file mode 100644 index 0000000..d0f64e9 Binary files /dev/null and b/out differ diff --git a/out.txt b/out.txt new file mode 100644 index 0000000..4114125 Binary files /dev/null and b/out.txt differ diff --git a/urmom b/urmom new file mode 100644 index 0000000..dc56d4b --- /dev/null +++ b/urmom @@ -0,0 +1 @@ +urmom \ No newline at end of file