dload.c : only call fwrite once

I assume the loop was never iterated more than once, because the write
location was not updated at each loop iteration (buffer instead of buffer +
nwritten), yet we never had reports of corrupted download.

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2009-08-08 15:20:24 +02:00 committed by Dan McGee
parent 68200676d2
commit 3cf0ee98c0

View file

@ -214,15 +214,13 @@ static int download_internal(const char *url, const char *localpath,
while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) { while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
size_t nwritten = 0; size_t nwritten = 0;
while(nwritten < nread) { nwritten = fwrite(buffer, 1, nread, localf);
nwritten += fwrite(buffer, 1, (nread - nwritten), localf); if((nwritten != nread) || ferror(localf)) {
if(ferror(localf)) {
_alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"), _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
destfile, strerror(errno)); destfile, strerror(errno));
ret = -1; ret = -1;
goto cleanup; goto cleanup;
} }
}
dl_thisfile += nread; dl_thisfile += nread;
if(handle->dlcb) { if(handle->dlcb) {