From 97327f1cd214e3b11516c04bd6a24c1a8089edd3 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Wed, 31 May 2006 16:18:16 +0000 Subject: * gdb/remote.c (remote_download_command): Correct short write handling. --- ChangeLog.csl | 5 +++++ 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 + + * gdb/remote.c (remote_download_command): Correct short write + handling. + 2006-05-23 Daniel Jacobowitz * 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; -- cgit v1.2.1