]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
* gdb/remote.c (remote_download_command): Correct short write
authorDaniel Jacobowitz <drow@false.org>
Wed, 31 May 2006 16:18:16 +0000 (16:18 +0000)
committerDaniel Jacobowitz <drow@false.org>
Wed, 31 May 2006 16:18:16 +0000 (16:18 +0000)
handling.

ChangeLog.csl
gdb/remote.c

index 82324794c8548aec6441038b93fe40b6ccefee36..cbb20ff7e045bc0ff18299b3cd493674cc535225 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-31  Daniel Jacobowitz  <dan@codesourcery.com>
+
+       * gdb/remote.c (remote_download_command): Correct short write
+       handling.
+
 2006-05-23  Daniel Jacobowitz  <dan@codesourcery.com>
 
        * gdb/remote.c (remote_fileio_errno_to_host)
index ab82a29144188346f111b8b1c62199ea4b98ce2e..15954c015da4a75f8cdb687982b7da7c9921084e 100644 (file)
@@ -6406,6 +6406,7 @@ remote_download_command (char *args, int from_tty)
   FILE *file;
   gdb_byte *buffer;
   int bytes_in_buffer;
+  int saw_eof;
 
   if (!remote_desc)
     error (_("command can only be used with remote target"));
@@ -6433,17 +6434,29 @@ remote_download_command (char *args, int from_tty)
   make_cleanup (xfree, buffer);
 
   bytes_in_buffer = 0;
-  while (1)
+  saw_eof = 0;
+  while (bytes_in_buffer || !saw_eof)
     {
-      bytes = fread (buffer, 1, 1024 - bytes_in_buffer, file);
-      if (bytes == 0)
+      if (!saw_eof)
        {
-         if (ferror (file))
-           error (_("Error reading %s."), argv[0]);
-         else
-           /* EOF */
-           break;
+         bytes = fread (buffer + bytes_in_buffer, 1, 1024 - bytes_in_buffer,
+                        file);
+         if (bytes == 0)
+           {
+             if (ferror (file))
+               error (_("Error reading %s."), argv[0]);
+             else
+               {
+                 /* EOF.  Unless there is something still in the
+                    buffer from the last iteration, we are done.  */
+                 saw_eof = 1;
+                 if (bytes_in_buffer == 0)
+                   break;
+               }
+           }
        }
+      else
+       bytes = 0;
 
       bytes += bytes_in_buffer;
       bytes_in_buffer = 0;