Process creation sequence reorganized:
[wine] / misc / xmalloc.c
1 /*
2    xmalloc - a safe malloc
3
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.
7
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).
11
12    Copyright 1995 by Morten Welinder.
13
14 */
15
16 #include <stdlib.h>
17 #include <string.h>
18 #include "xmalloc.h"
19 #include "debug.h"
20
21 void *xmalloc( int size )
22 {
23     void *res;
24
25     res = malloc (size ? size : 1);
26     if (res == NULL)
27     {
28         MSG("Virtual memory exhausted.\n");
29         exit (1);
30     }
31     memset(res,0,size);
32     return res;
33 }
34
35 void *xcalloc( int size )
36 {
37     void *res;
38
39     res = xmalloc (size);
40     memset(res,0,size);
41     return res;
42 }
43
44
45 void *xrealloc( void *ptr, int size )
46 {
47     void *res = realloc (ptr, size);
48     if ((res == NULL) && size)
49     {
50         MSG("Virtual memory exhausted.\n");
51         exit (1);
52     }
53     return res;
54 }
55
56
57 char *xstrdup( const char *str )
58 {
59     char *res = strdup( str );
60     if (!res)
61     {
62         MSG("Virtual memory exhausted.\n");
63         exit (1);
64     }
65     return res;
66 }