Sophie

Sophie

distrib > * > 2008.0 > x86_64 > by-pkgid > a62fc3f0285cc2de0a054bc489e77163 > files > 5

migration-assistant-0.5.1-3mdv2008.0.src.rpm

--- migration-assistant/utils.c.nommap	2007-07-31 15:26:05.000000000 +0200
+++ migration-assistant/utils.c	2007-08-01 10:05:33.000000000 +0200
@@ -68,7 +68,6 @@ char* reformat_path(const char* from) {
 // Modified from Advanced Programming in the Unix Environment.
 void copyfile(const char* from, const char* to) {
     int         fdin, fdout;
-    void        *src, *dst;
     struct stat statbuf;
     const int mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
 
@@ -94,30 +93,24 @@ void copyfile(const char* from, const ch
     if(statbuf.st_size == 0)
         return;
 
-    /* set size of output file */
-    if (lseek(fdout, statbuf.st_size - 1, SEEK_SET) == -1) {
-        puts("lseek error");
-	    exit(EXIT_FAILURE);
-    }
-    if (write(fdout, "", 1) != 1) {
-        puts("write error");
-	    exit(EXIT_FAILURE);
-    }
-
-    if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED,
-      fdin, 0)) == MAP_FAILED) {
-        puts("mmap error for input");
-	exit(EXIT_FAILURE);
+    /* does the file copy */
+    /* simplified version of coreutils/src/copy.c */
+    blksize_t blocksize = statbuf.st_blksize;
+    char *buf = alloca(blocksize);
+    for (;;) {
+        ssize_t n_read = read(fdin, buf, blocksize);
+        if (n_read < 0) {
+            printf("can't read in %s\n", from);
+            exit(EXIT_FAILURE);
+        }
+        if (n_read == 0)
+            break;
+        if (write(fdout, buf, n_read) != n_read) {
+            printf("can't write in %s\n", to);
+            exit(EXIT_FAILURE);
+        }
     }
 
-    if ((dst = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE,
-      MAP_SHARED, fdout, 0)) == MAP_FAILED) {
-        puts("mmap error for output");
-	exit(EXIT_FAILURE);
-    }
-
-    memcpy(dst, src, statbuf.st_size); /* does the file copy */
-
     close(fdin);
     close(fdout);
 }