diff options
author | Daniel Jacobowitz <dan@debian.org> | 2006-05-31 16:18:16 +0000 |
---|---|---|
committer | Daniel Jacobowitz <dan@debian.org> | 2006-05-31 16:18:16 +0000 |
commit | 97327f1cd214e3b11516c04bd6a24c1a8089edd3 (patch) | |
tree | 6cd00169fcf282929b5feaa23fe3599bf76608dc | |
parent | 9472bccc033a24c723ae619f4b0ca47587540531 (diff) | |
download | gdb-97327f1cd214e3b11516c04bd6a24c1a8089edd3.tar.gz |
* gdb/remote.c (remote_download_command): Correct short write
handling.
-rw-r--r-- | ChangeLog.csl | 5 | ||||
-rw-r--r-- | gdb/remote.c | 29 |
2 files changed, 26 insertions, 8 deletions
diff --git a/ChangeLog.csl b/ChangeLog.csl index 82324794c85..cbb20ff7e04 100644 --- a/ChangeLog.csl +++ b/ChangeLog.csl @@ -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) diff --git a/gdb/remote.c b/gdb/remote.c index ab82a291441..15954c015da 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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; |