New function: xalloc_and_zero()
[tinc] / lib / xmalloc.c
index ce1888d..037fab8 100644 (file)
@@ -20,6 +20,7 @@
 #endif
 
 #include <sys/types.h>
+#include <stdio.h>
 
 #if STDC_HEADERS
 # include <stdlib.h>
@@ -86,8 +87,6 @@ xmalloc (n)
      size_t n;
 {
   void *p;
-  extern char*cp_file;
-  extern int cp_line;
 
   p = malloc (n);
   if (p == 0)
@@ -95,6 +94,21 @@ xmalloc (n)
   return p;
 }
 
+/* Allocate N bytes of memory dynamically, and set it all to zero. */
+
+void *
+xmalloc_and_zero (n)
+     size_t n;
+{
+  void *p;
+
+  p = malloc (n);
+  if (p == 0)
+    xalloc_fail ((int)n);
+  memset (p, '\0', n);
+  return p;
+}
+
 /* Change the size of an allocated block of memory P to N bytes,
    with error checking.
    If P is NULL, run xmalloc.  */