File: misc.c

package info (click to toggle)
flin 0.5.1-9.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 276 kB
  • ctags: 164
  • sloc: ansic: 1,642; makefile: 105; sh: 71
file content (46 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (4)
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
/*
Copyright (C) 1995  Brian Cully

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.

please send patches or advice to: `shmit@kublai.com'
*/
#include <stdio.h>
#include <stdlib.h>

/* Print an error message (str) on stderr and exit */
void error(char *str, int line) {
   fprintf(stderr, "%i: %s", line, str);
   exit(1);
}

/*
 * chk_alloc()
 *
 * Input - size - number of bytes to allocate.
 * Returns - pointer to allocated space.
 *
 * This is a simple wrapper for malloc, so that we don't
 * need to worry about the return value of malloc being NULL
 */
void	*chk_alloc(size_t size)
{
	void	*retval;

	if ((retval = malloc(size)) == NULL)
		error("Out Of Memory!\n", 0);

	return(retval);
}