From: Daniel Jacobowitz Date: Wed, 31 May 2006 16:18:16 +0000 (+0000) Subject: * gdb/remote.c (remote_download_command): Correct short write X-Git-Tag: gdb-csl-symbian-6_4_50_20060226-9~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=73157ac1c49f4a38f78339ca6689e5af56b84946;p=thirdparty%2Fbinutils-gdb.git * gdb/remote.c (remote_download_command): Correct short write handling. --- 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;