@@ -26,6 +26,26 @@ Data types
2626 .. note ::
2727 On Windows this field is ULONG.
2828
29+ .. c :type :: void * (*uv_malloc_func)(size_t size)
30+
31+ Replacement function for :man:`malloc(3 )`.
32+ See :c:func:`uv_replace_allocator`.
33+
34+ .. c :type :: void * (*uv_realloc_func)(void * ptr, size_t size)
35+
36+ Replacement function for :man:`realloc(3 )`.
37+ See :c:func:`uv_replace_allocator`.
38+
39+ .. c :type :: void * (*uv_calloc_func)(size_t count, size_t size)
40+
41+ Replacement function for :man:`calloc(3 )`.
42+ See :c:func:`uv_replace_allocator`.
43+
44+ .. c :type :: void (*uv_free_func)(void * ptr)
45+
46+ Replacement function for :man:`free(3 )`.
47+ See :c:func:`uv_replace_allocator`.
48+
2949 .. c :type :: uv_file
3050
3151 Cross platform representation of a file handle.
126146 Returns the libuv version number as a string. For non-release versions
127147 "-pre" is appended, so the version number could be "1.2.3-pre".
128148
149+ .. c:function:: int uv_replace_allocator(uv_malloc_func malloc_func, uv_realloc_func realloc_func, uv_calloc_func calloc_func, uv_free_func free_func)
150+
151+ .. versionadded:: 1.6.0
152+
153+ Override the use of the standard library's :man:`malloc(3)`,
154+ :man:`calloc(3)`, :man:`realloc(3)`, :man:`free(3)`, memory allocation
155+ functions.
156+
157+ This function must be called before any other libuv function is called or
158+ after all resources have been freed and thus libuv doesn't reference
159+ any allocated memory chunk.
160+
161+ On success, it returns 0, if any of the function pointers is NULL it
162+ returns UV_EINVAL.
163+
164+ .. warning:: There is no protection against changing the allocator multiple
165+ times. If the user changes it they are responsible for making
166+ sure the allocator is changed while no memory was allocated with
167+ the previous allocator, or that they are compatible.
168+
129169.. c:function:: uv_buf_t uv_buf_init(char* base, unsigned int len)
130170
131171 Constructor for :c:type:`uv_buf_t`.
227267
228268 Changes the current working directory.
229269
270+ .. c:function:: int uv_os_homedir(char* buffer, size_t* size)
271+
272+ Gets the current user's home directory. On Windows, `uv_os_homedir()` first
273+ checks the `USERPROFILE` environment variable using
274+ `GetEnvironmentVariableW()`. If `USERPROFILE` is not set,
275+ `GetUserProfileDirectoryW()` is called. On all other operating systems,
276+ `uv_os_homedir()` first checks the `HOME` environment variable using
277+ :man:`getenv(3)`. If `HOME` is not set, :man:`getpwuid_r(3)` is called. The
278+ user's home directory is stored in `buffer`. When `uv_os_homedir()` is
279+ called, `size` indicates the maximum size of `buffer`. On success or
280+ `UV_ENOBUFS` failure, `size` is set to the string length of `buffer`.
281+
282+ .. warning::
283+ `uv_os_homedir()` is not thread safe.
284+
285+ .. versionadded:: 1.6.0
286+
230287.. uint64_t uv_get_free_memory(void)
231288.. c:function:: uint64_t uv_get_total_memory(void)
232289
0 commit comments