curl_global_init_mem.3 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. .\" generated by cd2nroff 0.1 from curl_global_init_mem.md
  2. .TH curl_global_init_mem 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_global_init_mem \- global libcurl initialization with memory callbacks
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLcode curl_global_init_mem(long flags,
  9. curl_malloc_callback m,
  10. curl_free_callback f,
  11. curl_realloc_callback r,
  12. curl_strdup_callback s,
  13. curl_calloc_callback c);
  14. .fi
  15. .SH DESCRIPTION
  16. This function works exactly as \fIcurl_global_init(3)\fP with one addition: it
  17. allows the application to set callbacks to replace the otherwise used internal
  18. memory functions.
  19. If you are using libcurl from multiple threads or libcurl was built with the
  20. threaded resolver option then the callback functions must be thread safe. The
  21. threaded resolver is a common build option to enable (and in some cases the
  22. default) so we strongly urge you to make your callback functions thread safe.
  23. All callback arguments must be set to valid function pointers. The
  24. prototypes for the given callbacks must match these:
  25. .IP "void *malloc_callback(size_t size);"
  26. To replace malloc()
  27. .IP "void free_callback(void *ptr);"
  28. To replace free()
  29. .IP "void *realloc_callback(void *ptr, size_t size);"
  30. To replace realloc()
  31. .IP "char *strdup_callback(const char *str);"
  32. To replace strdup()
  33. .IP "void *calloc_callback(size_t nmemb, size_t size);"
  34. To replace calloc()
  35. This function is otherwise the same as \fIcurl_global_init(3)\fP, please refer
  36. to that man page for documentation.
  37. .SH CAUTION
  38. Manipulating these gives considerable powers to the application to severely
  39. screw things up for libcurl. Take care!
  40. .SH PROTOCOLS
  41. This functionality affects all supported protocols
  42. .SH EXAMPLE
  43. .nf
  44. extern void *malloc_cb(size_t);
  45. extern void free_cb(void *);
  46. extern void *realloc_cb(void *, size_t);
  47. extern char *strdup_cb(const char *);
  48. extern void *calloc_cb(size_t, size_t);
  49. int main(void)
  50. {
  51. curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
  52. free_cb, realloc_cb,
  53. strdup_cb, calloc_cb);
  54. }
  55. .fi
  56. .SH AVAILABILITY
  57. Added in curl 7.12.0
  58. .SH RETURN VALUE
  59. CURLE_OK (0) means everything was OK, non\-zero means an error occurred as
  60. \fI<curl/curl.h>\fP defines \- see \fIlibcurl\-errors(3)\fP.
  61. .SH SEE ALSO
  62. .BR curl_global_cleanup (3),
  63. .BR curl_global_init (3)