Back to index

nagios-plugins  1.4.16
Defines | Functions
xalloc.h File Reference
#include <stddef.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define __attribute__(x)
#define ATTRIBUTE_NORETURN   __attribute__ ((__noreturn__))
#define ATTRIBUTE_MALLOC
#define xalloc_oversized(n, s)   ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))
#define XMALLOC(t)   ((t *) xmalloc (sizeof (t)))
#define XNMALLOC(n, t)   ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))
#define XZALLOC(t)   ((t *) xzalloc (sizeof (t)))
#define XCALLOC(n, t)   ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))

Functions

void xalloc_die (void) ATTRIBUTE_NORETURN
void * xmalloc (size_t s) ATTRIBUTE_MALLOC
void * xzalloc (size_t s) ATTRIBUTE_MALLOC
void * xcalloc (size_t n, size_t s) ATTRIBUTE_MALLOC
void * xrealloc (void *p, size_t s)
void * x2realloc (void *p, size_t *pn)
void * xmemdup (void const *p, size_t s) ATTRIBUTE_MALLOC
char * xstrdup (char const *str) ATTRIBUTE_MALLOC
void * xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC
void * xnrealloc (void *p, size_t n, size_t s)
void * x2nrealloc (void *p, size_t *pn, size_t s)
char * xcharalloc (size_t n) ATTRIBUTE_MALLOC

Define Documentation

#define __attribute__ (   x)

Definition at line 33 of file xalloc.h.

Definition at line 45 of file xalloc.h.

#define ATTRIBUTE_NORETURN   __attribute__ ((__noreturn__))

Definition at line 38 of file xalloc.h.

#define xalloc_oversized (   n,
 
)    ((size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) < (n))

Definition at line 76 of file xalloc.h.

#define XCALLOC (   n,
 
)    ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))

Definition at line 102 of file xalloc.h.

#define XMALLOC (   t)    ((t *) xmalloc (sizeof (t)))

Definition at line 87 of file xalloc.h.

#define XNMALLOC (   n,
 
)    ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t))))

Definition at line 91 of file xalloc.h.

#define XZALLOC (   t)    ((t *) xzalloc (sizeof (t)))

Definition at line 97 of file xalloc.h.


Function Documentation

void* x2nrealloc ( void *  p,
size_t *  pn,
size_t  s 
)

Here is the caller graph for this function:

void* x2realloc ( void *  p,
size_t *  pn 
)

Definition at line 70 of file xmalloc.c.

{
  return x2nrealloc (p, pn, 1);
}

Here is the call graph for this function:

void xalloc_die ( void  )

Definition at line 32 of file xalloc-die.c.

{
  error (exit_failure, 0, "%s", _("memory exhausted"));

  /* The `noreturn' cannot be given to error, since it may return if
     its first argument is 0.  To help compilers understand the
     xalloc_die does not return, call abort.  Also, the abort is a
     safety feature if exit_failure is 0 (which shouldn't happen).  */
  abort ();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* xcalloc ( size_t  n,
size_t  s 
)

Definition at line 89 of file xmalloc.c.

{
  void *p;
  /* Test for overflow, since some calloc implementations don't have
     proper overflow checks.  But omit overflow and size-zero tests if
     HAVE_GNU_CALLOC, since GNU calloc catches overflow and never
     returns NULL if successful.  */
  if ((! HAVE_GNU_CALLOC && xalloc_oversized (n, s))
      || (! (p = calloc (n, s)) && (HAVE_GNU_CALLOC || n != 0)))
    xalloc_die ();
  return p;
}

Here is the call graph for this function:

char* xcharalloc ( size_t  n)
void* xmalloc ( size_t  s)

Definition at line 43 of file xmalloc.c.

{
  void *p = malloc (n);
  if (!p && n != 0)
    xalloc_die ();
  return p;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* xmemdup ( void const p,
size_t  s 
)

Definition at line 107 of file xmalloc.c.

{
  return memcpy (xmalloc (s), p, s);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* xnmalloc ( size_t  n,
size_t  s 
)
void* xnrealloc ( void *  p,
size_t  n,
size_t  s 
)
void* xrealloc ( void *  p,
size_t  s 
)

Definition at line 55 of file xmalloc.c.

{
  p = realloc (p, n);
  if (!p && n != 0)
    xalloc_die ();
  return p;
}

Here is the call graph for this function:

char* xstrdup ( char const str)

Definition at line 115 of file xmalloc.c.

{
  return xmemdup (string, strlen (string) + 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* xzalloc ( size_t  s)

Definition at line 80 of file xmalloc.c.

{
  return memset (xmalloc (s), 0, s);
}

Here is the call graph for this function: