3 * Copyright (C) 1998-2005 A.J. van Os
6 * Extended malloc and friends
13 static char *szMessage
=
14 "Memory allocation failed, unable to continue";
15 #if defined(__dos) && !defined(__DJGPP__)
16 static char *szDosMessage
=
17 "DOS can't allocate this kind of memory, unable to continue";
18 #endif /* __dos && !__DJGPP__ */
22 * xmalloc - Allocates dynamic memory
24 * See malloc(3), but unlike malloc(3) xmalloc does not return in case
37 pvTmp
= malloc(tSize
);
39 DBG_MSG("xmalloc returned NULL");
44 } /* end of xmalloc */
47 * xcalloc - Allocates and zeros dynamic memory
49 * See calloc(3), but unlike calloc(3) xcalloc does not return in case of error
52 xcalloc(size_t tNmemb
, size_t tSize
)
58 #if defined(__dos) && !defined(__DJGPP__)
59 if ((ULONG
)tNmemb
* (ULONG
)tSize
> 0xffffUL
) {
60 DBG_DEC((ULONG
)tNmemb
* (ULONG
)tSize
);
61 werr(1, szDosMessage
);
63 #endif /* __dos && !__DJGPP__ */
65 if (tNmemb
== 0 || tSize
== 0) {
69 pvTmp
= calloc(tNmemb
, tSize
);
71 DBG_MSG("xcalloc returned NULL");
75 } /* end of xcalloc */
78 * xrealloc - Changes the size of a memory object
80 * See realloc(3), but unlike realloc(3) xrealloc does not return in case
84 xrealloc(void *pvArg
, size_t tSize
)
88 TRACE_MSG("xrealloc");
90 pvTmp
= realloc(pvArg
, tSize
);
92 DBG_MSG("realloc returned NULL");
96 } /* end of xrealloc */
99 * xstrdup - Duplicate a string
101 * See strdup(3), but unlike strdup(3) xstrdup does not return in case
105 * Does not use strdup(3), because some systems don't have it.
108 xstrdup(const char *szArg
)
112 TRACE_MSG("xstrdup");
114 szTmp
= xmalloc(strlen(szArg
) + 1);
115 strcpy(szTmp
, szArg
);
117 } /* end of xstrdup */
120 * xfree - Deallocates dynamic memory
125 * This makes p=xfree(p) possible, free memory and overwrite the pointer to it.