mirror of
https://github.com/nzp-team/dquakeplus.git
synced 2024-11-22 11:51:21 +00:00
Restore Q_* alloc features
This commit is contained in:
parent
688f57bab1
commit
9c0d864012
1 changed files with 62 additions and 0 deletions
|
@ -382,6 +382,68 @@ bytecopy:
|
|||
return (dst);
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Q_malloc
|
||||
Use it instead of malloc so that if memory allocation fails,
|
||||
the program exits with a message saying there's not enough memory
|
||||
instead of crashing after trying to use a NULL pointer
|
||||
===================
|
||||
*/
|
||||
void *Q_malloc (size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = malloc(size)))
|
||||
Sys_Error ("Not enough memory free; check disk space");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Q_calloc
|
||||
===================
|
||||
*/
|
||||
void *Q_calloc (size_t n, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = calloc(n, size)))
|
||||
Sys_Error ("Not enough memory free; check disk space");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Q_realloc
|
||||
===================
|
||||
*/
|
||||
void *Q_realloc (void *ptr, size_t size)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (!(p = realloc(ptr, size)))
|
||||
Sys_Error ("Not enough memory free; check disk space");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
===================
|
||||
Q_strdup
|
||||
===================
|
||||
*/
|
||||
void *Q_strdup (const char *str)
|
||||
{
|
||||
char *p;
|
||||
|
||||
if (!(p = strdup(str)))
|
||||
Sys_Error ("Not enough memory free; check disk space");
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
|
Loading…
Reference in a new issue