Select Git revision
testutils.c
testutils.c 36.34 KiB
/* testutils.c */
#include "testutils.h"
#include "base16.h"
#include "cbc.h"
#include "ctr.h"
#include "knuth-lfib.h"
#include "macros.h"
#include "nettle-internal.h"
#include <assert.h>
#include <ctype.h>
void
die(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
abort ();
}
void *
xalloc(size_t size)
{
void *p = malloc(size);
if (size && !p)
{
fprintf(stderr, "Virtual memory exhausted.\n");
abort();
}
return p;
}
static struct tstring *tstring_first = NULL;
struct tstring *
tstring_alloc (size_t length)
{
struct tstring *s = xalloc(sizeof(struct tstring) + length);
s->length = length;
s->next = tstring_first;
/* NUL-terminate, for convenience. */
s->data[length] = '\0';
tstring_first = s;
return s;
}
void
tstring_clear(void)
{
while (tstring_first)
{
struct tstring *s = tstring_first;
tstring_first = s->next;
free(s);
}
}
struct tstring *
tstring_data(size_t length, const char *data)
{
struct tstring *s = tstring_alloc (length);
memcpy (s->data, data, length);
return s;
}