Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdlib add recallocarray



details:   https://anonhg.NetBSD.org/src/rev/d6f710c10366
branches:  trunk
changeset: 356663:d6f710c10366
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Oct 07 19:38:35 2017 +0000

description:
add recallocarray

diffstat:

 lib/libc/stdlib/reallocarray.c |  17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diffs (38 lines):

diff -r 4f260010a65e -r d6f710c10366 lib/libc/stdlib/reallocarray.c
--- a/lib/libc/stdlib/reallocarray.c    Sat Oct 07 19:38:09 2017 +0000
+++ b/lib/libc/stdlib/reallocarray.c    Sat Oct 07 19:38:35 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: reallocarray.c,v 1.7 2016/04/06 11:07:58 roy Exp $     */
+/*     $NetBSD: reallocarray.c,v 1.8 2017/10/07 19:38:35 christos Exp $        */
 /*     $OpenBSD: reallocarray.c,v 1.1 2014/05/08 21:43:49 deraadt Exp $        */
 
 /*-
@@ -31,10 +31,11 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: reallocarray.c,v 1.7 2016/04/06 11:07:58 roy Exp $");
+__RCSID("$NetBSD: reallocarray.c,v 1.8 2017/10/07 19:38:35 christos Exp $");
 
 #define _OPENBSD_SOURCE
 #include <errno.h>
+#include <string.h>
 #include <stdlib.h>
 
 void *
@@ -51,3 +52,15 @@
        errno = e;
        return NULL;
 }
+
+void *
+recallocarray(void *optr, size_t omemb, size_t nmemb, size_t size)
+{
+       char *nptr = reallocarray(optr, nmemb, size);
+
+       if (nptr == NULL || omemb >= nmemb)
+               return nptr;
+
+       memset(nptr + omemb * size, 0, (nmemb - omemb) * size);
+       return nptr;
+}



Home | Main Index | Thread Index | Old Index