32#if HAVE_MALLOC_MALLOC_H
33#include <malloc/malloc.h>
36#define LOG(kind, ...) \
37 GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__)
39#define LOG_STRERROR(kind, syscall) \
40 GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
43#define INT_MAX 0x7FFFFFFF
133 uint64_t *base = ptr;
134 size_t s = M_SIZE (ptr);
138 const uint64_t baadfood =
GNUNET_ntohll (0xBAADF00DBAADF00DLL);
145 for (
size_t i = 1 + (n + 7) / 8; i < s / 8; i++)
154 ptr = realloc (ptr, n);
155 if ((NULL == ptr) && (n > 0))
165#if __BYTE_ORDER == __LITTLE_ENDIAN
166#define BAADFOOD_STR "\x0D\xF0\xAD\xBA"
168#if __BYTE_ORDER == __BIG_ENDIAN
169#define BAADFOOD_STR "\xBA\xAD\xF0\x0D"
173#include <malloc_np.h>
175#if HAVE_MALLOC_USABLE_SIZE
176#define M_SIZE(p) malloc_usable_size (p)
177#elif HAVE_MALLOC_SIZE
178#define M_SIZE(p) malloc_size (p)
191 const uint64_t baadfood =
GNUNET_ntohll (0xBAADF00DBAADF00DLL);
192 uint64_t *base = ptr;
193 size_t s = M_SIZE (ptr);
195 for (
size_t i = 0; i < s / 8; i++)
210 size_t slen = strlen (str) + 1;
271 unsigned int *oldCount,
272 unsigned int newCount,
281 size = newCount * elementSize;
307 *oldCount = newCount;
321 ret = vsnprintf (NULL,
328 va_start (
args, format);
329 ret = vsnprintf (*buf,
349 ret = vsnprintf (buf,
379 for (
size_t i = 0; i < n; i++)
struct GNUNET_MessageHeader * msg
static size_t strnlen(const char *s, size_t n)
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
int GNUNET_asprintf(char **buf, const char *format,...)
#define LOG_STRERROR(kind, syscall)
static int ret
Final status code.
static char * res
Currently read line or NULL on EOF.
static int result
Global testing status.
char * GNUNET_xstrndup_(const char *str, size_t len, const char *filename, int linenumber)
Dup partially a string.
void GNUNET_xgrow_(void **old, size_t elementSize, unsigned int *oldCount, unsigned int newCount, const char *filename, int linenumber)
Grow an array, the new elements are zeroed out.
char * GNUNET_xstrdup_(const char *str, const char *filename, int linenumber)
Dup a string.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
void * GNUNET_xmalloc_unchecked_(size_t size, const char *filename, int linenumber)
Allocate memory.
void GNUNET_xfree_(void *ptr, const char *filename, int linenumber)
Free memory.
void * GNUNET_xrealloc_(void *ptr, size_t n, const char *filename, int linenumber)
Reallocate memory.
void * GNUNET_xmalloc_(size_t size, const char *filename, int linenumber)
Allocate memory.
bool GNUNET_is_zero_(const void *a, size_t n)
Check that memory in a is all zeros.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void * GNUNET_xmemdup_(const void *buf, size_t size, const char *filename, int linenumber)
Allocate and initialize memory.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_assert_at(cond, f, l)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_MAX_MALLOC_CHECKED
Maximum allocation with GNUNET_malloc macro.
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.
#define GNUNET_malloc(size)
Wrapper around malloc.
static unsigned int size
Size of the "table".