File: xmalloc.c

package info (click to toggle)
birthday 1.6.2-3
  • links: PTS
  • area: main
  • in suites: lenny, squeeze, wheezy
  • size: 464 kB
  • ctags: 168
  • sloc: ansic: 1,401; makefile: 54; sh: 44; perl: 31
file content (40 lines) | stat: -rw-r--r-- 712 bytes parent folder | download | duplicates (5)
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
/*
	xmalloc/xrealloc functions, and fatal exit function

	Note: the x* functions are lifted straight from the GNU libc info docs
	
	$Id: xmalloc.c,v 1.2 2005/07/19 18:50:00 andymort Exp $
*/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

#include "xmalloc.h"

void *xmalloc (size_t size)
{
  register void *value = malloc (size);
  if (value == 0)
    fatal ("virtual memory exhausted\n");
  return value;
}

void *xrealloc (void *ptr, size_t size)
{
  register void *value = realloc (ptr, size);
  if (value == 0)
    fatal ("Virtual memory exhausted\n");
  return value;
}

void fatal(char *fmt, ...)
{
  va_list ap;

  va_start(ap, fmt);
  vfprintf(stderr, fmt, ap);
  va_end(ap);

  exit(1);
}