summaryrefslogtreecommitdiffstats
path: root/hack/alloc.c
blob: 68713b210a5cc22707a3351e64b2455f5244316e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*	$NetBSD: alloc.c,v 1.4 1997/10/19 16:56:47 christos Exp $	*/
#include <sys/cdefs.h>
#ifndef lint
__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"

#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 *
alloc(n)
	unsigned        n;
{
	long            dummy = ftell(stderr);
	if (n)
		dummy = 0;	/* make sure arg is used */
	return (&dummy);
}

#else

long *
alloc(lth)
	unsigned lth;
{
	char  *ptr;

	if (!(ptr = malloc(lth)))
		panic("Cannot get %d bytes", lth);
	return ((long *) ptr);
}

long *
enlarge(ptr, lth)
	char  *ptr;
	unsigned lth;
{
	char  *nptr;

	if (!(nptr = realloc(ptr, lth)))
		panic("Cannot reallocate %d bytes", lth);
	return ((long *) nptr);
}

#endif	/* LINT */