GNUnet  0.17.6
Macros | Functions
common_allocation.c File Reference

wrapper around malloc/free More...

#include "platform.h"
#include "gnunet_crypto_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_xnew_array_2d_ (size_t n, size_t m, size_t elementSize, const char *filename, int linenumber)
 Allocate memory for a two dimensional array in one block and set up pointers. More...
 
void *** GNUNET_xnew_array_3d_ (size_t n, size_t m, size_t o, size_t elementSize, const char *filename, int linenumber)
 Allocate memory for a three dimensional array in one block and set up pointers. 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)
 Wrapper around malloc(). 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 (same semantics as strdup). 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 (same semantics as strndup). More...
 
void GNUNET_xgrow_ (void **old, size_t elementSize, unsigned int *oldCount, unsigned int newCount, const char *filename, int linenumber)
 Grow an array. More...
 
int GNUNET_asprintf (char **buf, const char *format,...)
 Like asprintf(), just portable. More...
 
int GNUNET_snprintf (char *buf, size_t size, const char *format,...)
 Like snprintf(), just aborts if the buffer is of insufficient size. More...
 
struct GNUNET_MessageHeaderGNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
 Create a copy of the given message. More...
 
enum GNUNET_GenericReturnValue 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 35 of file common_allocation.c.

◆ LOG_STRERROR

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

Definition at line 38 of file common_allocation.c.

◆ INT_MAX

#define INT_MAX   0x7FFFFFFF

Definition at line 42 of file common_allocation.c.

◆ BAADFOOD_STR [1/2]

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

Definition at line 262 of file common_allocation.c.

◆ BAADFOOD_STR [2/2]

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

Definition at line 262 of file common_allocation.c.

Function Documentation

◆ strnlen()

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

Definition at line 330 of file common_allocation.c.

331 {
332  const char *e;
333 
334  e = memchr (s, '\0', n);
335  if (NULL == e)
336  return n;
337  return e - s;
338 }
static struct Experiment * e

References e.

Referenced by convert_with_table(), and GNUNET_xstrndup_().

Here is the caller graph for this function:

◆ GNUNET_asprintf()

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

Like asprintf(), just portable.

Parameters
bufset to a buffer of sufficient size (allocated, caller must free)
formatformat string (see printf(), fprintf(), etc.)
...data for format string
Returns
number of bytes in *@a buf, excluding 0-termination

Definition at line 428 of file common_allocation.c.

429 {
430  int ret;
431  va_list args;
432 
433  va_start (args, format);
434  ret = vsnprintf (NULL, 0, format, args);
435  va_end (args);
436  GNUNET_assert (ret >= 0);
437  *buf = GNUNET_malloc (ret + 1);
438  va_start (args, format);
439  ret = vsprintf (*buf, format, args);
440  va_end (args);
441  return ret;
442 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char buf[2048]
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.

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

◆ GNUNET_snprintf()

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

Like snprintf(), just aborts if the buffer is of insufficient size.

Parameters
bufpointer to buffer that is written to
sizenumber of bytes in buf
formatformat strings
...data for format string
Returns
number of bytes written to buf or negative value on error

Definition at line 455 of file common_allocation.c.

456 {
457  int ret;
458  va_list args;
459 
460  va_start (args, format);
461  ret = vsnprintf (buf, size, format, args);
462  va_end (args);
463  GNUNET_assert ((ret >= 0) && (((size_t) ret) < size));
464  return ret;
465 }
static unsigned int size
Size of the "table".
Definition: peer.c:67

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