GNUnet 0.22.2
common_allocation.c File Reference

wrapper around malloc/free More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for common_allocation.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)    GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__)
 
#define LOG_STRERROR(kind, syscall)    GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
 
#define INT_MAX   0x7FFFFFFF
 
#define BAADFOOD_STR   "\x0D\xF0\xAD\xBA"
 
#define BAADFOOD_STR   "\xBA\xAD\xF0\x0D"
 

Functions

void * GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
 Allocate memory. More...
 
void * GNUNET_xmemdup_ (const void *buf, size_t size, const char *filename, int linenumber)
 Allocate and initialize memory. More...
 
void * GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
 Allocate memory. More...
 
void * GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber)
 Reallocate memory. More...
 
void GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
 Free memory. More...
 
char * GNUNET_xstrdup_ (const char *str, const char *filename, int linenumber)
 Dup a string. More...
 
static size_t strnlen (const char *s, size_t n)
 
char * GNUNET_xstrndup_ (const char *str, size_t len, const char *filename, int linenumber)
 Dup partially a string. More...
 
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. More...
 
int GNUNET_asprintf (char **buf, const char *format,...)
 
int GNUNET_snprintf (char *buf, size_t size, const char *format,...)
 
struct GNUNET_MessageHeaderGNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
 Create a copy of the given message. More...
 
bool GNUNET_is_zero_ (const void *a, size_t n)
 Check that memory in a is all zeros. More...
 

Detailed Description

wrapper around malloc/free

Author
Christian Grothoff

Definition in file common_allocation.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)     GNUNET_log_from (kind, "util-common-allocation", __VA_ARGS__)

Definition at line 36 of file common_allocation.c.

◆ LOG_STRERROR

#define LOG_STRERROR (   kind,
  syscall 
)     GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)

Definition at line 39 of file common_allocation.c.

◆ INT_MAX

#define INT_MAX   0x7FFFFFFF

Definition at line 43 of file common_allocation.c.

◆ BAADFOOD_STR [1/2]

#define BAADFOOD_STR   "\x0D\xF0\xAD\xBA"

Definition at line 169 of file common_allocation.c.

◆ BAADFOOD_STR [2/2]

#define BAADFOOD_STR   "\xBA\xAD\xF0\x0D"

Definition at line 169 of file common_allocation.c.

Function Documentation

◆ strnlen()

static size_t strnlen ( const char *  s,
size_t  n 
)
static

Definition at line 228 of file common_allocation.c.

230{
231 const char *e;
232
233 e = memchr (s,
234 '\0',
235 n);
236 if (NULL == e)
237 return n;
238 return e - s;
239}

Referenced by GNUNET_strlcpy(), GNUNET_xstrndup_(), and handle_gns_resolution_result().

Here is the caller graph for this function:

◆ GNUNET_asprintf()

int GNUNET_asprintf ( char **  buf,
const char *  format,
  ... 
)

Definition at line 312 of file common_allocation.c.

315{
316 int ret;
317 va_list args;
318
319 va_start (args,
320 format);
321 ret = vsnprintf (NULL,
322 0,
323 format,
324 args);
325 va_end (args);
326 GNUNET_assert (ret >= 0);
327 *buf = GNUNET_malloc (ret + 1);
328 va_start (args, format);
329 ret = vsnprintf (*buf,
330 ret + 1,
331 format,
332 args);
333 va_end (args);
334 return ret;
335}
static int ret
Final status code.
Definition: gnunet-arm.c:93
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.

References consensus-simulation::args, GNUNET_assert, GNUNET_malloc, and ret.

◆ GNUNET_snprintf()

int GNUNET_snprintf ( char *  buf,
size_t  size,
const char *  format,
  ... 
)

Definition at line 339 of file common_allocation.c.

343{
344 int ret;
345 va_list args;
346
347 va_start (args,
348 format);
349 ret = vsnprintf (buf,
350 size,
351 format,
352 args);
353 va_end (args);
354 GNUNET_assert ((ret >= 0) && (((size_t) ret) < size));
355 return ret;
356}
static unsigned int size
Size of the "table".
Definition: peer.c:68

References consensus-simulation::args, GNUNET_assert, ret, and size.