buf_size: check pointer size earlier
[smatch.git] / utils.h
blob7bd14f4677991256c7c29b7e1a0616518f4bec29
1 #ifndef UTILS_H
2 #define UTILS_H
4 ///
5 // Miscellaneous utilities
6 // -----------------------
8 #include <stddef.h>
9 #include <stdarg.h>
11 ///
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);
19 ///
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);
26 ///
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, ...);
34 ///
35 // vprintf to allocated string
36 // @fmt: the format
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);
43 #endif