Release 971012
[wine/multimedia.git] / misc / xmalloc.c
bloba228f71a5b5a2791e1c24772da9dcce1e8c690f2
1 /*
2 xmalloc - a safe malloc
4 Use this function instead of malloc whenever you don't intend to check
5 the return value yourself, for instance because you don't have a good
6 way to handle a zero return value.
8 Typically, Wine's own memory requests should be handled by this function,
9 while the clients should use malloc directly (and Wine should return an
10 error to the client if allocation fails).
12 Copyright 1995 by Morten Welinder.
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include "xmalloc.h"
21 void *xmalloc( int size )
23 void *res;
25 res = malloc (size ? size : 1);
26 if (res == NULL)
28 fprintf (stderr, "Virtual memory exhausted.\n");
29 exit (1);
31 return res;
35 void *xrealloc( void *ptr, int size )
37 void *res = realloc (ptr, size);
38 if ((res == NULL) && size)
40 fprintf (stderr, "Virtual memory exhausted.\n");
41 exit (1);
43 return res;
47 char *xstrdup( const char *str )
49 char *res = strdup( str );
50 if (!res)
52 fprintf (stderr, "Virtual memory exhausted.\n");
53 exit (1);
55 return res;