Skip to content

Commit 5c3d5a3

Browse files
glandiumgitster
authored andcommitted
Make fread/fwrite-like functions in http.c more like fread/fwrite.
The fread/fwrite-like functions in http.c, namely fread_buffer, fwrite_buffer, fwrite_null, fwrite_sha1_file all return the multiplication of the size and number of items they are being given. Practically speaking, it doesn't matter, because in all contexts where those functions are used, size is 1. But those functions being similar to fread and fwrite (the curl API is designed around being able to use fread and fwrite directly), it might be preferable to make them behave like fread and fwrite, which, from the fread/fwrite manual page, is: On success, fread() and fwrite() return the number of items read or written. This number equals the number of bytes transferred only when size is 1. If an error occurs, or the end of the file is reached, the return value is a short item count (or zero). Signed-off-by: Mike Hommey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83232e3 commit 5c3d5a3

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)