NetBSD/games/hack/alloc.c

56 lines
956 B
C
Raw Normal View History

1997-10-19 20:56:41 +04:00
/* $NetBSD: alloc.c,v 1.4 1997/10/19 16:56:47 christos Exp $ */
#include <sys/cdefs.h>
#ifndef lint
1997-10-19 20:56:41 +04:00
__RCSID("$NetBSD: alloc.c,v 1.4 1997/10/19 16:56:47 christos Exp $");
#endif /* not lint */
#include <stdlib.h>
#include "hack.h"
#include "extern.h"
1993-03-21 12:45:37 +03:00
#ifdef LINT
/*
a ridiculous definition, suppressing
"possible pointer alignment problem" for (long *) malloc()
"enlarg defined but never used"
"ftell defined (in <stdio.h>) but never used"
from lint
*/
long *
1997-10-19 20:56:41 +04:00
alloc(n)
unsigned n;
{
long dummy = ftell(stderr);
if (n)
dummy = 0; /* make sure arg is used */
return (&dummy);
1993-03-21 12:45:37 +03:00
}
#else
long *
alloc(lth)
1997-10-19 20:56:41 +04:00
unsigned lth;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
char *ptr;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!(ptr = malloc(lth)))
1993-03-21 12:45:37 +03:00
panic("Cannot get %d bytes", lth);
1997-10-19 20:56:41 +04:00
return ((long *) ptr);
1993-03-21 12:45:37 +03:00
}
long *
1997-10-19 20:56:41 +04:00
enlarge(ptr, lth)
char *ptr;
unsigned lth;
1993-03-21 12:45:37 +03:00
{
1997-10-19 20:56:41 +04:00
char *nptr;
1993-03-21 12:45:37 +03:00
1997-10-19 20:56:41 +04:00
if (!(nptr = realloc(ptr, lth)))
1993-03-21 12:45:37 +03:00
panic("Cannot reallocate %d bytes", lth);
1997-10-19 20:56:41 +04:00
return ((long *) nptr);
1993-03-21 12:45:37 +03:00
}
1997-10-19 20:56:41 +04:00
#endif /* LINT */