~ubuntu-branches/ubuntu/quantal/curl/quantal-updates

« back to all changes in this revision

Viewing changes to docs/examples/getinmemory.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * $Id: getinmemory.c,v 1.12 2007-11-07 04:53:37 danf Exp $
 
8
 * $Id: getinmemory.c,v 1.13 2008-09-06 04:28:45 yangtse Exp $
9
9
 *
10
10
 * Example source code to show how the callback function can be used to
11
11
 * download data into a chunk of memory instead of storing it in a file.
26
26
  size_t size;
27
27
};
28
28
 
 
29
static void *myrealloc(void *ptr, size_t size);
 
30
 
29
31
static void *myrealloc(void *ptr, size_t size)
30
32
{
31
33
  /* There might be a realloc() out there that doesn't like reallocing
42
44
  size_t realsize = size * nmemb;
43
45
  struct MemoryStruct *mem = (struct MemoryStruct *)data;
44
46
 
45
 
  mem->memory = (char *)myrealloc(mem->memory, mem->size + realsize + 1);
 
47
  mem->memory = myrealloc(mem->memory, mem->size + realsize + 1);
46
48
  if (mem->memory) {
47
49
    memcpy(&(mem->memory[mem->size]), ptr, realsize);
48
50
    mem->size += realsize;