]> jfr.im git - irc/quakenet/newserv.git/blobdiff - core/nsmalloc.c
PROXYSCAN: gline for 12h now by default.
[irc/quakenet/newserv.git] / core / nsmalloc.c
index df3b10e8871e24e48491f59482be74295f070a60..0575c55c05f913f9ab21388876d6c2719d5b50d4 100644 (file)
@@ -1,6 +1,7 @@
 /* nsmalloc: Simple pooled malloc() thing. */
 
 #include <stdlib.h>
+#include <string.h>
 
 #include "nsmalloc.h"
 #define __NSMALLOC_C
@@ -39,6 +40,19 @@ void *nsmalloc(unsigned int poolid, size_t size) {
   return (void *)nsmp->data;
 }
 
+void *nscalloc(unsigned int poolid, size_t nmemb, size_t size) {
+  size_t total = nmemb * size;
+  void *m;
+
+  m = nsmalloc(poolid, total);
+  if(!m)
+    return NULL;
+
+  memset(m, 0, total);
+
+  return m;
+}
+
 /* we dump core on ptr == NULL */
 void nsfree(unsigned int poolid, void *ptr) {
   struct nsminfo *nsmp;
@@ -118,7 +132,7 @@ void nscheckfreeall(unsigned int poolid) {
     return;
  
   if (nsmpools[poolid].first.next) {
-    Error("core",ERR_INFO,"nsmalloc: Blocks still allocated in pool #%d (%s): %lub, %lu items",poolid,nsmpoolnames[poolid]?nsmpoolnames[poolid]:"??",nsmpools[poolid].size,nsmpools[poolid].count);
+    Error("core",ERR_INFO,"nsmalloc: Blocks still allocated in pool #%d (%s): %zub, %lu items",poolid,nsmpoolnames[poolid]?nsmpoolnames[poolid]:"??",nsmpools[poolid].size,nsmpools[poolid].count);
     nsfreeall(poolid);
   }
 }
@@ -136,6 +150,10 @@ void *nsmalloc(unsigned int poolid, size_t size) {
   return malloc(size);
 }
 
+void *nscalloc(unsigned int poolid, size_t nmemb, size_t size) {
+  return calloc(nmemb, size);
+}
+
 void *nsrealloc(unsigned int poolid, void *ptr, size_t size) {
   return realloc(ptr, size);
 }