function_hooks: do set_fresh_mtag_returns() later
[smatch.git] / utils.h
blob079fb02a3e94c4eca6649c447371013ceeaafccb
1 #ifndef UTILS_H
2 #define UTILS_H
4 ///
5 // Miscellaneous utilities
6 // -----------------------
8 #include <stddef.h>
9 #include <stdarg.h>
11 ///
12 // return the value coresponding to an hexadecimal digit
13 unsigned int hexval(unsigned int c);
15 ///
16 // duplicate a memory buffer in a newly allocated buffer.
17 // @src: a pointer to the memory buffer to be duplicated
18 // @len: the size of the memory buffer to be duplicated
19 // @return: a pointer to a copy of @src allocated via
20 // :func:`__alloc_bytes()`.
21 void *xmemdup(const void *src, size_t len);
23 ///
24 // duplicate a null-terminated string in a newly allocated buffer.
25 // @src: a pointer to string to be duplicated
26 // @return: a pointer to a copy of @str allocated via
27 // :func:`__alloc_bytes()`.
28 char *xstrdup(const char *src);
30 ///
31 // printf to allocated string
32 // @fmt: the format followed by its arguments.
33 // @return: the allocated & formatted string.
34 // This function is similar to asprintf() but the resulting string
35 // is allocated with __alloc_bytes().
36 char *xasprintf(const char *fmt, ...);
38 ///
39 // vprintf to allocated string
40 // @fmt: the format
41 // @ap: the variadic arguments
42 // @return: the allocated & formatted string.
43 // This function is similar to asprintf() but the resulting string
44 // is allocated with __alloc_bytes().
45 char *xvasprintf(const char *fmt, va_list ap);
47 #endif