quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

curl_global_init_mem.md (2603B)


      1 ---
      2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
      3 SPDX-License-Identifier: curl
      4 Title: curl_global_init_mem
      5 Section: 3
      6 Source: libcurl
      7 See-also:
      8   - curl_global_cleanup (3)
      9   - curl_global_init (3)
     10 Protocol:
     11   - All
     12 Added-in: 7.12.0
     13 ---
     14 
     15 # NAME
     16 
     17 curl_global_init_mem - global libcurl initialization with memory callbacks
     18 
     19 # SYNOPSIS
     20 
     21 ~~~c
     22 #include <curl/curl.h>
     23 
     24 CURLcode curl_global_init_mem(long flags,
     25                               curl_malloc_callback m,
     26                               curl_free_callback f,
     27                               curl_realloc_callback r,
     28                               curl_strdup_callback s,
     29                               curl_calloc_callback c);
     30 ~~~
     31 
     32 # DESCRIPTION
     33 
     34 This function works exactly as curl_global_init(3) with one addition: it
     35 allows the application to set callbacks to replace the otherwise used internal
     36 memory functions.
     37 
     38 If you are using libcurl from multiple threads or libcurl was built with the
     39 threaded resolver option then the callback functions must be thread safe. The
     40 threaded resolver is a common build option to enable (and in some cases the
     41 default) so we strongly urge you to make your callback functions thread safe.
     42 
     43 All callback arguments must be set to valid function pointers. The
     44 prototypes for the given callbacks must match these:
     45 
     46 ## `void *malloc_callback(size_t size);`
     47 
     48 To replace malloc()
     49 
     50 ## `void free_callback(void *ptr);`
     51 
     52 To replace free()
     53 
     54 ## `void *realloc_callback(void *ptr, size_t size);`
     55 
     56 To replace realloc()
     57 
     58 ## `char *strdup_callback(const char *str);`
     59 
     60 To replace strdup()
     61 
     62 ## `void *calloc_callback(size_t nmemb, size_t size);`
     63 
     64 To replace calloc()
     65 
     66 This function is otherwise the same as curl_global_init(3), please refer
     67 to that man page for documentation.
     68 
     69 # CAUTION
     70 
     71 Manipulating these gives considerable powers to the application to severely
     72 screw things up for libcurl. Take care.
     73 
     74 # %PROTOCOLS%
     75 
     76 # EXAMPLE
     77 
     78 ~~~c
     79 extern void *malloc_cb(size_t);
     80 extern void free_cb(void *);
     81 extern void *realloc_cb(void *, size_t);
     82 extern char *strdup_cb(const char *);
     83 extern void *calloc_cb(size_t, size_t);
     84 
     85 int main(void)
     86 {
     87   curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
     88                        free_cb, realloc_cb,
     89                        strdup_cb, calloc_cb);
     90 }
     91 ~~~
     92 
     93 # %AVAILABILITY%
     94 
     95 # RETURN VALUE
     96 
     97 This function returns a CURLcode indicating success or error.
     98 
     99 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
    100 libcurl-errors(3). If CURLOPT_ERRORBUFFER(3) was set with curl_easy_setopt(3)
    101 there can be an error message stored in the error buffer when non-zero is
    102 returned.