/** * Copyright © 2005 Atheme Development Group * Rights to this code are documented in doc/pod/license.pod. * * Memory functions. */ static char const rcsid[] = "$Id: memory.C,v 1.5 2007/08/28 17:12:24 pippijn dead $"; #include "atheme.h" std::vector gc::mortals; /* does malloc()'s job and dies if malloc() fails */ void * smalloc (size_t size) { void *buf = calloc (size, 1); if (!buf) raise (SIGUSR1); return buf; } /* does calloc()'s job and dies if calloc() fails */ void * scalloc (size_t elsize, size_t els) { void *buf = calloc (elsize, els); if (!buf) raise (SIGUSR1); return buf; } /* does realloc()'s job and dies if realloc() fails */ void * srealloc (void *oldptr, size_t newsize) { void *buf = realloc (oldptr, newsize); if (!buf) raise (SIGUSR1); return buf; } /* does strdup()'s job, only with the above memory functions */ char * sstrdup (char const *s) { char *t; if (s == NULL) return NULL; t = static_cast < char *>(smalloc (strlen (s) + 1)); strcpy (t, s); return t; } /* does strndup()'s job, only with the above memory functions */ char * sstrndup (char const *s, int len) { char *t; if (s == NULL) return NULL; t = static_cast < char *>(smalloc (len + 1)); strlcpy (t, s, len); return t; }