1#ifndef UTILS_H 2#define UTILS_H 3 4/// 5// Miscellaneous utilities 6// ----------------------- 7 8#include <stddef.h> 9#include <stdarg.h> 10 11/// 12// return the value coresponding to an hexadecimal digit 13unsigned int hexval(unsigned int c); 14 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()`. 21void *xmemdup(const void *src, size_t len); 22 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()`. 28char *xstrdup(const char *src); 29 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(). 36char *xasprintf(const char *fmt, ...); 37 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(). 45char *xvasprintf(const char *fmt, va_list ap); 46 47#endif 48