More reliable copying in key saving.
[u/mdw/catacomb] / key-file.c
index 15b0304..6e422b1 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: key-file.c,v 1.3 2004/04/08 01:36:15 mdw Exp $
+ * $Id$
  *
  * System-dependent key filing operations
  *
@@ -60,6 +60,7 @@
 static int fdcopy(int source, int dest)
 {
   char buf[4096];
+  char *p;
 
   if (lseek(source, 0, SEEK_SET) < 0||
       lseek(dest, 0, SEEK_SET) < 0 ||
@@ -71,8 +72,14 @@ static int fdcopy(int source, int dest)
       return (-1);
     else if (n == 0)
       break;
-    else if (write(dest, buf, n) < 0)
-      return (-1);
+    p = buf;
+    while (n) {
+      int nn = write(dest, p, n);
+      if (nn < 0)
+       return (-1);
+      p += nn;
+      n -= nn;
+    }
   }
   return (0);
 }