* Functions to dynamically allocate arrays.
*/
+/* Additionan debug messages related to array handling: 0=off / 1=on */
+#define DEBUG_ARRAY 0
+
#include "array.h"
#include <assert.h>
-
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
-#include "log.h"
-
-/* Enable more Debug messages in alloc / append / memmove code. */
-/* #define DEBUG_ARRAY */
+#if DEBUG_ARRAY
+# include "log.h"
+#endif
+#define array_UNUSABLE(x) ( !(x)->mem )
-#define array_UNUSABLE(x) ( !(x)->mem )
static bool
safemult_sizet(size_t a, size_t b, size_t *res)
{
return NULL;
if (a->allocated < alloc) {
-#ifdef DEBUG_ARRAY
+#if DEBUG_ARRAY
Log(LOG_DEBUG, "array_alloc(): changing size from %u to %u bytes.",
a->allocated, alloc);
#endif
assert(ptr != NULL);
-#ifdef DEBUG_ARRAY
+#if DEBUG_ARRAY
Log(LOG_DEBUG,
"array_catb(): appending %u bytes to array (now %u bytes in array).",
len, tmp);
array_free(array * a)
{
assert(a != NULL);
-#ifdef DEBUG_ARRAY
+#if DEBUG_ARRAY
Log(LOG_DEBUG,
"array_free(): %u bytes free'd (%u bytes still used at time of free()).",
a->allocated, a->used);
if (!bytepos)
return; /* nothing to do */
-#ifdef DEBUG_ARRAY
+#if DEBUG_ARRAY
Log(LOG_DEBUG,
"array_moveleft(): %u bytes used in array, starting at position %u.",
a->used, bytepos);