From 81f87f58edd08fa100fab6a8df1ddc13f9907822 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 13 Apr 2009 23:57:12 +0000 Subject: [PATCH] When clearing a device we do now ignore an error when we could write anything at all. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30151 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tools/create_image.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/tools/create_image.cpp b/src/tools/create_image.cpp index 7f79f46bf1..cec280e19a 100644 --- a/src/tools/create_image.cpp +++ b/src/tools/create_image.cpp @@ -131,11 +131,16 @@ main(int argc, char *argv[]) char buffer[1024 * 1024]; memset(buffer, 0, sizeof(buffer)); + off_t totalWritten = 0; ssize_t written; - while ((written = write(fd, buffer, sizeof(buffer))) > 0) { - } + while ((written = write(fd, buffer, sizeof(buffer))) > 0) + totalWritten += written; - if (written < 0) { + // Only fail, if an error occurs and we haven't written anything at + // all yet. + // TODO: We should probably first determine the size of the device + // and try to write only that much. + if (totalWritten == 0 && written < 0) { fprintf(stderr, "Error: writing to device file %s failed " "(%s)\n", file, strerror(errno)); exit(EXIT_FAILURE);