Skip to content

Commit f6af2d3

Browse files
committed
Merge branch 'mh/http-fread-api-fix' into next
A pair of private functions in http.c that had names similar to fread/fwrite did not return the number of elements, which was found to be confusing. * mh/http-fread-api-fix: Make fread/fwrite-like functions in http.c more like fread/fwrite.
2 parents 24e5e27 + 5c3d5a3 commit f6af2d3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

http.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ size_t fread_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
176176
memcpy(ptr, buffer->buf.buf + buffer->posn, size);
177177
buffer->posn += size;
178178

179-
return size;
179+
return size / eltsize;
180180
}
181181

182182
#ifndef NO_CURL_IOCTL
@@ -204,12 +204,12 @@ size_t fwrite_buffer(char *ptr, size_t eltsize, size_t nmemb, void *buffer_)
204204
struct strbuf *buffer = buffer_;
205205

206206
strbuf_add(buffer, ptr, size);
207-
return size;
207+
return nmemb;
208208
}
209209

210210
size_t fwrite_null(char *ptr, size_t eltsize, size_t nmemb, void *strbuf)
211211
{
212-
return eltsize * nmemb;
212+
return nmemb;
213213
}
214214

215215
static void closedown_active_slot(struct active_request_slot *slot)
@@ -2319,14 +2319,14 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
23192319
BUG("curl_easy_getinfo for HTTP code failed: %s",
23202320
curl_easy_strerror(c));
23212321
if (slot->http_code >= 300)
2322-
return size;
2322+
return nmemb;
23232323
}
23242324

23252325
do {
23262326
ssize_t retval = xwrite(freq->localfile,
23272327
(char *) ptr + posn, size - posn);
23282328
if (retval < 0)
2329-
return posn;
2329+
return posn / eltsize;
23302330
posn += retval;
23312331
} while (posn < size);
23322332

@@ -2339,7 +2339,7 @@ static size_t fwrite_sha1_file(char *ptr, size_t eltsize, size_t nmemb,
23392339
the_hash_algo->update_fn(&freq->c, expn,
23402340
sizeof(expn) - freq->stream.avail_out);
23412341
} while (freq->stream.avail_in && freq->zret == Z_OK);
2342-
return size;
2342+
return nmemb;
23432343
}
23442344

23452345
struct http_object_request *new_http_object_request(const char *base_url,

0 commit comments

Comments
 (0)