5 // Miscellaneous utilities
6 // -----------------------
12 // duplicate a memory buffer in a newly allocated buffer.
13 // @src: a pointer to the memory buffer to be duplicated
14 // @len: the size of the memory buffer to be duplicated
15 // @return: a pointer to a copy of @src allocated via
16 // :func:`__alloc_bytes()`.
17 void *xmemdup(const void *src
, size_t len
);
20 // duplicate a null-terminated string in a newly allocated buffer.
21 // @src: a pointer to string to be duplicated
22 // @return: a pointer to a copy of @str allocated via
23 // :func:`__alloc_bytes()`.
24 char *xstrdup(const char *src
);
27 // printf to allocated string
28 // @fmt: the format followed by its arguments.
29 // @return: the allocated & formatted string.
30 // This function is similar to asprintf() but the resulting string
31 // is allocated with __alloc_bytes().
32 char *xasprintf(const char *fmt
, ...);
35 // vprintf to allocated string
37 // @ap: the variadic arguments
38 // @return: the allocated & formatted string.
39 // This function is similar to asprintf() but the resulting string
40 // is allocated with __alloc_bytes().
41 char *xvasprintf(const char *fmt
, va_list ap
);