curl_global_init_mem.3 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .TH curl_global_init_mem 3 "10 May 2004" "libcurl" "libcurl"
  25. .SH NAME
  26. curl_global_init_mem - Global libcurl initialization with memory callbacks
  27. .SH SYNOPSIS
  28. .nf
  29. #include <curl/curl.h>
  30. CURLcode curl_global_init_mem(long flags,
  31. curl_malloc_callback m,
  32. curl_free_callback f,
  33. curl_realloc_callback r,
  34. curl_strdup_callback s,
  35. curl_calloc_callback c);
  36. .fi
  37. .SH DESCRIPTION
  38. This function works exactly as \fIcurl_global_init(3)\fP with one addition: it
  39. allows the application to set callbacks to replace the otherwise used internal
  40. memory functions.
  41. If you are using libcurl from multiple threads or libcurl was built with the
  42. threaded resolver option then the callback functions must be thread safe. The
  43. threaded resolver is a common build option to enable (and in some cases the
  44. default) so we strongly urge you to make your callback functions thread safe.
  45. All callback arguments must be set to valid function pointers. The
  46. prototypes for the given callbacks must match these:
  47. .IP "void *malloc_callback(size_t size);"
  48. To replace malloc()
  49. .IP "void free_callback(void *ptr);"
  50. To replace free()
  51. .IP "void *realloc_callback(void *ptr, size_t size);"
  52. To replace realloc()
  53. .IP "char *strdup_callback(const char *str);"
  54. To replace strdup()
  55. .IP "void *calloc_callback(size_t nmemb, size_t size);"
  56. To replace calloc()
  57. .PP
  58. This function is otherwise the same as \fIcurl_global_init(3)\fP, please refer
  59. to that man page for documentation.
  60. .SH CAUTION
  61. Manipulating these gives considerable powers to the application to severely
  62. screw things up for libcurl. Take care!
  63. .SH EXAMPLE
  64. .nf
  65. curl_global_init_mem(CURL_GLOBAL_DEFAULT, curl_malloc_cb,
  66. curl_free_cb, curl_realloc_cb,
  67. curl_strdup_cb, curl_calloc_cb);
  68. .fi
  69. .SH AVAILABILITY
  70. Added in 7.12.0
  71. .SH RETURN VALUE
  72. CURLE_OK (0) means everything was OK, non-zero means an error occurred as
  73. \fI<curl/curl.h>\fP defines - see \fIlibcurl-errors(3)\fP.
  74. .SH "SEE ALSO"
  75. .BR curl_global_init "(3), "
  76. .BR curl_global_cleanup "(3), "