mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
811ce26663
git-svn-id: svn://svn.anope.org/anope/trunk@4 31f1291d-b8d6-0310-a050-a5561fc1590b git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2 5417fbe8-f217-4b02-8779-1006273d7864
97 lines
2.0 KiB
C
97 lines
2.0 KiB
C
/* Memory management routines.
|
|
*
|
|
* (C) 2003 Anope Team
|
|
* Contact us at info@anope.org
|
|
*
|
|
* Please read COPYING and README for furhter details.
|
|
*
|
|
* Based on the original code of Epona by Lara.
|
|
* Based on the original code of Services by Andy Church.
|
|
*
|
|
* $Id$
|
|
*
|
|
*/
|
|
|
|
#include "services.h"
|
|
|
|
/*************************************************************************/
|
|
/*************************************************************************/
|
|
|
|
/* smalloc, scalloc, srealloc, sstrdup:
|
|
* Versions of the memory allocation functions which will cause the
|
|
* program to terminate with an "Out of memory" error if the memory
|
|
* cannot be allocated. (Hence, the return value from these functions
|
|
* is never NULL.)
|
|
*/
|
|
|
|
void *smalloc(long size)
|
|
{
|
|
void *buf;
|
|
|
|
if (!size) {
|
|
size = 1;
|
|
}
|
|
buf = malloc(size);
|
|
if (!buf)
|
|
#if !defined(USE_THREADS) || !defined(LINUX20)
|
|
raise(SIGUSR1);
|
|
#else
|
|
abort();
|
|
#endif
|
|
return buf;
|
|
}
|
|
|
|
void *scalloc(long elsize, long els)
|
|
{
|
|
void *buf;
|
|
|
|
if (!elsize || !els) {
|
|
elsize = els = 1;
|
|
}
|
|
buf = calloc(elsize, els);
|
|
if (!buf)
|
|
#if !defined(USE_THREADS) || !defined(LINUX20)
|
|
raise(SIGUSR1);
|
|
#else
|
|
abort();
|
|
#endif
|
|
return buf;
|
|
}
|
|
|
|
void *srealloc(void *oldptr, long newsize)
|
|
{
|
|
void *buf;
|
|
|
|
if (!newsize) {
|
|
newsize = 1;
|
|
}
|
|
buf = realloc(oldptr, newsize);
|
|
if (!buf)
|
|
#if !defined(USE_THREADS) || !defined(LINUX20)
|
|
raise(SIGUSR1);
|
|
#else
|
|
abort();
|
|
#endif
|
|
return buf;
|
|
}
|
|
|
|
char *sstrdup(const char *s)
|
|
{
|
|
char *t = strdup(s);
|
|
if (!t)
|
|
#if !defined(USE_THREADS) || !defined(LINUX20)
|
|
raise(SIGUSR1);
|
|
#else
|
|
abort();
|
|
#endif
|
|
return t;
|
|
}
|
|
|
|
/*************************************************************************/
|
|
/*************************************************************************/
|
|
|
|
/* In the future: malloc() replacements that tell us if we're leaking and
|
|
* maybe do sanity checks too... */
|
|
|
|
/*************************************************************************/
|