#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
char *malloc_options = "jj";
static void
testerrno(size_t sz)
{
void *p;
errno = -1;
p = malloc(sz);
if (p == NULL && errno != ENOMEM)
errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno);
if (p != NULL && errno != -1)
errx(1, "fail: %lx %p %d", (unsigned long)sz, p, errno);
free(p);
}
int
main(int argc, char *argv[])
{
size_t i;
testerrno(1);
testerrno(100000);
testerrno(-1);
testerrno(-1000);
testerrno(-10000);
testerrno(-10000000);
for (i = 0; i < 0x10; i++)
testerrno(i * 0x10000000);
return 0;
}