Release 960114
[wine/gsoc-2012-control.git] / misc / xmalloc.c
blob58b9681359daa059974c461f573af830ea5a56da
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 handles by this function,
9 while the client's 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 <string.h>
18 #include "xmalloc.h"
20 void *
21 xmalloc (size_t 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 *
36 xrealloc (void *ptr, size_t size)
38 void *res = realloc (ptr, size);
39 if (res == NULL)
41 fprintf (stderr, "Virtual memory exhausted.\n");
42 exit (1);
44 return res;
48 char *xstrdup( const char *str )
50 char *res = strdup( str );
51 if (!res)
53 fprintf (stderr, "Virtual memory exhausted.\n");
54 exit (1);
56 return res;