Release 960218
[wine/testsucceed.git] / misc / xmalloc.c
blobd79bd20c08107525e1f08ccd9ec05b270f7efdf6
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 <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;