From 0a0c98d37666027f8182714200e454406c6dd282 Mon Sep 17 00:00:00 2001 From: des Date: Tue, 27 Sep 2011 15:57:13 +0000 Subject: Followup to r225599: the fseek() was a no-op since the file was opened in append mode. Open it in read-write mode instead. Also move the fseek up one level to cover the (unlikely but not impossible) case where the server accepts ranges but does not send a Content-Size header. PR: bin/117277 MFC after: 3 weeks --- usr.bin/fetch/fetch.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'usr.bin/fetch/fetch.c') diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c index d0e97ec..267deac 100644 --- a/usr.bin/fetch/fetch.c +++ b/usr.bin/fetch/fetch.c @@ -540,7 +540,7 @@ fetch(char *URL, const char *path) goto failure; } /* we got it, open local file */ - if ((of = fopen(path, "a")) == NULL) { + if ((of = fopen(path, "r+")) == NULL) { warn("%s: fopen()", path); goto failure; } @@ -559,13 +559,13 @@ fetch(char *URL, const char *path) sb = nsb; /* picked up again later */ } - /* seek to where we left off */ - if (of != NULL && fseek(of, url->offset, SEEK_SET) != 0) { - warn("%s: fseek()", path); - fclose(of); - of = NULL; - /* picked up again later */ - } + } + /* seek to where we left off */ + if (of != NULL && fseek(of, url->offset, SEEK_SET) != 0) { + warn("%s: fseek()", path); + fclose(of); + of = NULL; + /* picked up again later */ } } else if (m_flag && sb.st_size != -1) { /* mirror mode, local file exists */ -- cgit v1.1