Back to index

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

Go to the source code of this file.

Defines

#define safe_alloca(N)   ((void) (N), NULL)
#define malloca(N)   mmalloca (N)
#define freea   free
#define nmalloca(n, s)
#define sa_alignof(type)   offsetof (struct { char __slot1; type __slot2; }, __slot2)

Enumerations

enum  {
  sa_alignment_long = sa_alignof (long), sa_alignment_double = sa_alignof (double), sa_alignment_longdouble = sa_alignof (long double), sa_alignment_max,
  sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
}

Functions

void * mmalloca (size_t n)

Define Documentation

#define freea   free

Definition at line 70 of file malloca.h.

#define malloca (   N)    mmalloca (N)

Definition at line 61 of file malloca.h.

#define nmalloca (   n,
 
)
Value:
((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \
     ? NULL \
     : malloca ((n) * (s)))

Definition at line 79 of file malloca.h.

#define sa_alignof (   type)    offsetof (struct { char __slot1; type __slot2; }, __slot2)

Definition at line 110 of file malloca.h.

#define safe_alloca (   N)    ((void) (N), NULL)

Definition at line 49 of file malloca.h.


Enumeration Type Documentation

anonymous enum
Enumerator:
sa_alignment_long 
sa_alignment_double 
sa_alignment_longdouble 
sa_alignment_max 
sa_increment 

Definition at line 113 of file malloca.h.

{
/* The desired alignment of memory allocations is the maximum alignment
   among all elementary types.  */
  sa_alignment_long = sa_alignof (long),
  sa_alignment_double = sa_alignof (double),
#if HAVE_LONG_LONG_INT
  sa_alignment_longlong = sa_alignof (long long),
#endif
  sa_alignment_longdouble = sa_alignof (long double),
  sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
#if HAVE_LONG_LONG_INT
                      | (sa_alignment_longlong - 1)
#endif
                      | (sa_alignment_longdouble - 1)
                     ) + 1,
/* The increment that guarantees room for a magic word must be >= sizeof (int)
   and a multiple of sa_alignment_max.  */
  sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
};

Function Documentation

void* mmalloca ( size_t  n)

Definition at line 68 of file malloca.c.

{
#if HAVE_ALLOCA
  /* Allocate one more word, that serves as an indicator for malloc()ed
     memory, so that freea() of an alloca() result is fast.  */
  size_t nplus = n + HEADER_SIZE;

  if (nplus >= n)
    {
      char *p = (char *) malloc (nplus);

      if (p != NULL)
        {
          size_t slot;

          p += HEADER_SIZE;

          /* Put a magic number into the indicator word.  */
          ((int *) p)[-1] = MAGIC_NUMBER;

          /* Enter p into the hash table.  */
          slot = (unsigned long) p % HASH_TABLE_SIZE;
          ((struct header *) (p - HEADER_SIZE))->next = mmalloca_results[slot];
          mmalloca_results[slot] = p;

          return p;
        }
    }
  /* Out of memory.  */
  return NULL;
#else
# if !MALLOC_0_IS_NONNULL
  if (n == 0)
    n = 1;
# endif
  return malloc (n);
#endif
}