Refactor the curl PUT read callback

This commit is contained in:
Travis Cross 2014-07-04 07:47:04 +00:00
parent 2fea35282f
commit c17d58b856
1 changed files with 3 additions and 8 deletions

View File

@ -153,16 +153,11 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb, void *data)
static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
{
struct data_stream *dstream = (struct data_stream*)stream;
size_t nmax = size*nmemb, ncur = 0;
if (dstream->length > nmax) {
ncur = nmax;
dstream->length -= nmax;
} else {
ncur = dstream->length;
dstream->length = 0;
}
size_t nmax = size*nmemb;
size_t ncur = (dstream->length > nmax) ? nmax : dstream->length;
memmove(ptr, dstream->data, ncur);
dstream->data += ncur;
dstream->length -= ncur;
return ncur;
}