git: 9front

Download patch

ref: a88ac3898fad1757a1c174cc55371d1785282aec
parent: ab8c89b0bd4c55c472f2a137a0175d35648517a5
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Nov 5 14:00:10 EDT 2016

libc: move calloc() into its own compilation unit

move calloc() in its own compilation unit to avoid
code duplication. also, calloc() is used rarely in
plan9 programs.

--- a/sys/src/9/port/alloc.c
+++ b/sys/src/9/port/alloc.c
@@ -286,15 +286,6 @@
 	return poolmsize(mainmem, (ulong*)v-Npadlong)-Npadlong*sizeof(ulong);
 }
 
-void*
-calloc(ulong n, ulong szelem)
-{
-	void *v;
-	if(v = mallocz(n*szelem, 1))
-		setmalloctag(v, getcallerpc(&n));
-	return v;
-}
-
 /* secret memory, used to back cryptographic keys and cipher states */
 void*
 secalloc(ulong size)
--- /dev/null
+++ b/sys/src/libc/port/calloc.c
@@ -1,0 +1,13 @@
+#include <u.h>
+#include <libc.h>
+
+void*
+calloc(ulong n, ulong s)
+{
+	void *v;
+	if(n > 1 && ((ulong)-1)/n < s)
+		return nil;
+	if(v = mallocz(n*s, 1))
+		setmalloctag(v, getcallerpc(&n));
+	return v;
+}
--- a/sys/src/libc/port/malloc.c
+++ b/sys/src/libc/port/malloc.c
@@ -279,18 +279,6 @@
 	return poolmsize(mainmem, (ulong*)v-Npadlong)-Npadlong*sizeof(ulong);
 }
 
-void*
-calloc(ulong n, ulong s)
-{
-	void *v;
-
-	if(n > 1 && ((ulong)-1)/n < s)
-		return nil;
-	if(v = mallocz(n*s, 1))
-		setmalloctag(v, getcallerpc(&n));
-	return v;
-}
-
 void
 setmalloctag(void *v, uintptr pc)
 {
--- a/sys/src/libc/port/mkfile
+++ b/sys/src/libc/port/mkfile
@@ -12,6 +12,7 @@
 	atof.c\
 	atol.c\
 	atoll.c\
+	calloc.c\
 	cistrcmp.c\
 	cistrncmp.c\
 	cistrstr.c\
--