From 2457a319481fb5eaccda3a79e8c3f2b8623ab70c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 13:03:53 +0000 Subject: an example on how you can use the write callback to receive data in a memory chunk --- docs/examples/getinmemory.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 docs/examples/getinmemory.c (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c new file mode 100644 index 000000000..3304a1dbd --- /dev/null +++ b/docs/examples/getinmemory.c @@ -0,0 +1,81 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * $Id$ + * + * Example source code to show how the callback function can be used to + * download data into a chunk of memory instead of storing it in a file. + * + * This exact source code has not been verified to work. + */ + +/* to make this work under windows, use the win32-functions from the + win32socket.c file as well */ + +#include + +#include +#include +#include + +struct MemoryStruct { + char *memory; + size_t size; +}; + +size_t +WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +{ + register int realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)data; + + mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory) { + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + } + return realsize; +} + +int main(int argc, char **argv) +{ + CURL *curl; + CURLcode res; + + struct MemoryStruct chunk; + + chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ + chunk.size = 0; /* no data at this point */ + + /* init the curl session */ + curl_handle = curl_easy_init(); + + /* specify URL to get */ + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://cool.haxx.se/"); + + /* send all data to this function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&chunk); + + /* get it! */ + curl_easy_perform(curl_handle); + + /* cleanup curl stuff */ + curl_easy_cleanup(curl_handle); + + /* + * Now, our chunk.memory points to a memory block that is chunk.size + * bytes big and contains the remote file. + * + * Do something nice with it! + */ + + return 0; +} -- cgit v1.2.1 From 3ceb2bcbb9cc3e77c6401ece5b05720779f459e9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 15 May 2001 13:04:53 +0000 Subject: this might actually compile too... --- docs/examples/getinmemory.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 3304a1dbd..afd6e3f03 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -44,8 +44,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) int main(int argc, char **argv) { - CURL *curl; - CURLcode res; + CURL *curl_handle; struct MemoryStruct chunk; -- cgit v1.2.1 From ebe5191b631a093fb9ad37b778d51b39d86c1966 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 10 Mar 2003 17:01:11 +0000 Subject: no the data is not freed, this is left for the app to do when needed --- docs/examples/getinmemory.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index afd6e3f03..7d6629123 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -74,6 +74,10 @@ int main(int argc, char **argv) * bytes big and contains the remote file. * * Do something nice with it! + * + * You should be aware of the fact that at this point we might have an + * allocated data block, and nothing has yet deallocated that data. So when + * you're done with it, you should free() it as a nice application. */ return 0; -- cgit v1.2.1 From 4d280124683a7d57cacb14729f964aec21eba7d7 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 Nov 2003 08:19:20 +0000 Subject: remove the wrong win32 comment and use global_init --- docs/examples/getinmemory.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 7d6629123..e45beb070 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -13,9 +13,6 @@ * This exact source code has not been verified to work. */ -/* to make this work under windows, use the win32-functions from the - win32socket.c file as well */ - #include #include @@ -51,6 +48,8 @@ int main(int argc, char **argv) chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ chunk.size = 0; /* no data at this point */ + curl_global_init(CURL_GLOBAL_ALL); + /* init the curl session */ curl_handle = curl_easy_init(); -- cgit v1.2.1 From f68219ddaab9dab05a195a6fd126b4edb5ecccdc Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 8 Dec 2003 14:13:19 +0000 Subject: use the newer option names --- docs/examples/getinmemory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index e45beb070..f7e27460f 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -60,7 +60,7 @@ int main(int argc, char **argv) curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); /* we pass our 'chunk' struct to the callback function */ - curl_easy_setopt(curl_handle, CURLOPT_FILE, (void *)&chunk); + curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); /* get it! */ curl_easy_perform(curl_handle); -- cgit v1.2.1 From 662cb303729cfb4f875ee3ed9486122e193cc16c Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 May 2004 09:08:19 +0000 Subject: Set CURLOPT_USERAGENT too --- docs/examples/getinmemory.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index f7e27460f..c1b6e12d4 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -62,6 +62,10 @@ int main(int argc, char **argv) /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); + /* some servers don't like requests that are made withput a user-agent + field, so we provide one */ + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); + /* get it! */ curl_easy_perform(curl_handle); -- cgit v1.2.1 From a94e117ede4712420a86ade19e6e74ee8b1046f3 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 19 May 2004 09:09:31 +0000 Subject: language! --- docs/examples/getinmemory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index c1b6e12d4..10ce8551f 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -62,7 +62,7 @@ int main(int argc, char **argv) /* we pass our 'chunk' struct to the callback function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); - /* some servers don't like requests that are made withput a user-agent + /* some servers don't like requests that are made without a user-agent field, so we provide one */ curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); -- cgit v1.2.1 From 186f433e4038b697b40f66a293f0f15332d055c4 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Nov 2004 08:26:55 +0000 Subject: modified to not use realloc() on a NULL pointer --- docs/examples/getinmemory.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 10ce8551f..5a77e9c7e 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -1,8 +1,8 @@ /***************************************************************************** - * _ _ ____ _ - * Project ___| | | | _ \| | - * / __| | | | |_) | | - * | (__| |_| | _ <| |___ + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * * $Id$ @@ -24,13 +24,23 @@ struct MemoryStruct { size_t size; }; +void *myrealloc(void *ptr, size_t size) +{ + /* There might be a realloc() out there that doesn't like reallocing + NULL pointers, so we take care of it here */ + if(ptr) + return realloc(ptr, size); + else + return malloc(size); +} + size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { register int realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; - - mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1); + + mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); if (mem->memory) { memcpy(&(mem->memory[mem->size]), ptr, realsize); mem->size += realsize; -- cgit v1.2.1 From 2248599ae140b03d1d369cfb45cb14b4aea21891 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 4 Feb 2005 23:53:12 +0000 Subject: fix type --- docs/examples/getinmemory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 5a77e9c7e..3ca3aedd2 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -37,7 +37,7 @@ void *myrealloc(void *ptr, size_t size) size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { - register int realsize = size * nmemb; + size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); -- cgit v1.2.1 From ab1f5c3edd55910c967bafcb5385ddeaf9dc53e2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 10 Oct 2005 20:58:18 +0000 Subject: make it compile warning-free and free() the memory before exit --- docs/examples/getinmemory.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 3ca3aedd2..00ed39eb2 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -14,6 +14,8 @@ */ #include +#include +#include #include #include @@ -93,5 +95,8 @@ int main(int argc, char **argv) * you're done with it, you should free() it as a nice application. */ + if(chunk.memory) + free(chunk.memory); + return 0; } -- cgit v1.2.1 From 4706a9334149f656eef9b5e8888da1ead23b0941 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Mon, 16 Jul 2007 21:22:12 +0000 Subject: Fixed some more simple compile warnings in the examples. --- docs/examples/getinmemory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 00ed39eb2..e80aa4165 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -26,7 +26,7 @@ struct MemoryStruct { size_t size; }; -void *myrealloc(void *ptr, size_t size) +static void *myrealloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing NULL pointers, so we take care of it here */ @@ -36,7 +36,7 @@ void *myrealloc(void *ptr, size_t size) return malloc(size); } -size_t +static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { size_t realsize = size * nmemb; -- cgit v1.2.1 From 70f10f1ac9270d67ceec53f3db5f76af8532c5e0 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Wed, 7 Nov 2007 04:53:37 +0000 Subject: Add a call to curl_global_cleanup to show how to do a proper shutdown. --- docs/examples/getinmemory.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index e80aa4165..fc1f87a91 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -98,5 +98,8 @@ int main(int argc, char **argv) if(chunk.memory) free(chunk.memory); + /* we're done with libcurl, so clean it up */ + curl_global_cleanup(); + return 0; } -- cgit v1.2.1 From 861b647e7b1da564b831a5b07312a30feb7b6c58 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Sat, 6 Sep 2008 04:28:43 +0000 Subject: remove unnecessary typecasting of realloc() --- docs/examples/getinmemory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index fc1f87a91..c92482166 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -26,6 +26,8 @@ struct MemoryStruct { size_t size; }; +static void *myrealloc(void *ptr, size_t size); + static void *myrealloc(void *ptr, size_t size) { /* There might be a realloc() out there that doesn't like reallocing @@ -42,7 +44,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1); + mem->memory = myrealloc(mem->memory, mem->size + realsize + 1); if (mem->memory) { memcpy(&(mem->memory[mem->size]), ptr, realsize); mem->size += realsize; -- cgit v1.2.1 From 2309b4e330b96bc2e1f8e36b6184015e59544037 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 24 Mar 2010 11:02:54 +0100 Subject: remove the CVSish $Id$ lines --- docs/examples/getinmemory.c | 1 - 1 file changed, 1 deletion(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index c92482166..5a66a04ca 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -5,7 +5,6 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * $Id$ * * Example source code to show how the callback function can be used to * download data into a chunk of memory instead of storing it in a file. -- cgit v1.2.1 From fbefd816e493a2c690e342bd3e91ce6e5300f31e Mon Sep 17 00:00:00 2001 From: James Bursa Date: Tue, 14 Sep 2010 22:52:04 +0200 Subject: getinmemory: make the example easier to follow 1. Remove the comment warning that it's "not been verified to work". It works with no problems in my testing. 2. Remove 2 unnecessary includes. 3. Remove the myrealloc(). Initialize chunk.memory with malloc() instead of NULL. The comments for these two parts contradicted each other. 4. Handle out of memory from realloc() instead of continuing. 5. Print a brief status message at the end. --- docs/examples/getinmemory.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 5a66a04ca..2e34f1787 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -8,8 +8,6 @@ * * Example source code to show how the callback function can be used to * download data into a chunk of memory instead of storing it in a file. - * - * This exact source code has not been verified to work. */ #include @@ -17,25 +15,12 @@ #include #include -#include -#include struct MemoryStruct { char *memory; size_t size; }; -static void *myrealloc(void *ptr, size_t size); - -static void *myrealloc(void *ptr, size_t size) -{ - /* There might be a realloc() out there that doesn't like reallocing - NULL pointers, so we take care of it here */ - if(ptr) - return realloc(ptr, size); - else - return malloc(size); -} static size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) @@ -43,22 +28,28 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) size_t realsize = size * nmemb; struct MemoryStruct *mem = (struct MemoryStruct *)data; - mem->memory = myrealloc(mem->memory, mem->size + realsize + 1); - if (mem->memory) { - memcpy(&(mem->memory[mem->size]), ptr, realsize); - mem->size += realsize; - mem->memory[mem->size] = 0; + mem->memory = realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory == NULL) { + /* out of memory! */ + printf("not enough memory (realloc returned NULL)\n"); + exit(EXIT_FAILURE); } + + memcpy(&(mem->memory[mem->size]), ptr, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + return realsize; } + int main(int argc, char **argv) { CURL *curl_handle; struct MemoryStruct chunk; - chunk.memory=NULL; /* we expect realloc(NULL, size) to work */ + chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ chunk.size = 0; /* no data at this point */ curl_global_init(CURL_GLOBAL_ALL); @@ -96,6 +87,8 @@ int main(int argc, char **argv) * you're done with it, you should free() it as a nice application. */ + printf("%lu bytes retrieved\n", chunk.size); + if(chunk.memory) free(chunk.memory); -- cgit v1.2.1 From 18e7b52e8e95f7204d8ef7ff0f0ff0043afe45a9 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 5 Oct 2010 15:00:19 +0200 Subject: examples: use example.com in example URLs --- docs/examples/getinmemory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 2e34f1787..635a936ba 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) curl_handle = curl_easy_init(); /* specify URL to get */ - curl_easy_setopt(curl_handle, CURLOPT_URL, "http://cool.haxx.se/"); + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.example.com/"); /* send all data to this function */ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); -- cgit v1.2.1 From 9583b4af9057c9e35ec3dd3270d4c4813b5f7aaa Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 17 Dec 2010 23:34:26 +0100 Subject: examples: fix compiler warnings --- docs/examples/getinmemory.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 635a936ba..85b049483 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -43,7 +43,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) } -int main(int argc, char **argv) +int main(void) { CURL *curl_handle; @@ -87,7 +87,7 @@ int main(int argc, char **argv) * you're done with it, you should free() it as a nice application. */ - printf("%lu bytes retrieved\n", chunk.size); + printf("%lu bytes retrieved\n", (long)chunk.size); if(chunk.memory) free(chunk.memory); -- cgit v1.2.1 From 1aeb635cdd296c16acb375a4a83a78f13166ccab Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 10 Mar 2011 11:48:02 +0100 Subject: sources: update source headers All C and H files now (should) feature the proper project curl source code header, which includes basic info, a copyright statement and some basic disclaimers. --- docs/examples/getinmemory.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index 85b049483..b5b34d4f0 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -1,12 +1,25 @@ -/***************************************************************************** +/*************************************************************************** * _ _ ____ _ * Project ___| | | | _ \| | * / __| | | | |_) | | * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * + * Copyright (C) 1998 - 2011, Daniel Stenberg, , et al. * - * Example source code to show how the callback function can be used to + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +/* Example source code to show how the callback function can be used to * download data into a chunk of memory instead of storing it in a file. */ -- cgit v1.2.1 From 450975b0c34bcc9659cbb963460b3e4d0df43543 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 7 Sep 2011 22:43:28 +0200 Subject: getinmemory.c: use better argument names for write callback --- docs/examples/getinmemory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/examples/getinmemory.c') diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c index b5b34d4f0..78e6deb10 100644 --- a/docs/examples/getinmemory.c +++ b/docs/examples/getinmemory.c @@ -36,10 +36,10 @@ struct MemoryStruct { static size_t -WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) +WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; - struct MemoryStruct *mem = (struct MemoryStruct *)data; + struct MemoryStruct *mem = (struct MemoryStruct *)userp; mem->memory = realloc(mem->memory, mem->size + realsize + 1); if (mem->memory == NULL) { @@ -48,7 +48,7 @@ WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) exit(EXIT_FAILURE); } - memcpy(&(mem->memory[mem->size]), ptr, realsize); + memcpy(&(mem->memory[mem->size]), contents, realsize); mem->size += realsize; mem->memory[mem->size] = 0; -- cgit v1.2.1