aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-05-25 16:01:36 +0200
committerDuncaen <mail@duncano.de>2017-05-25 16:01:36 +0200
commit3d10a78d84cd6497ab671465e23e5b7de8b938f2 (patch)
treeb91b12a48e9c76befbd326badf6b9ccf7cf485da
parent32d200ea3ef5644890fe9db306c6a4a5cead8873 (diff)
downloadlobase-3d10a78d84cd6497ab671465e23e5b7de8b938f2.tar.gz
lib/libopenbsd: add freezero(3)
-rw-r--r--include/stdlib.h1
-rw-r--r--lib/libopenbsd/stdlib/Makefile.inc4
-rw-r--r--lib/libopenbsd/stdlib/freezero.c32
3 files changed, 37 insertions, 0 deletions
diff --git a/include/stdlib.h b/include/stdlib.h
index 3828118..ca74ab7 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -43,6 +43,7 @@ uint32_t arc4random_uniform(uint32_t);
void arc4random_buf(void *, size_t)
__attribute__((__bounded__ (__string__,1,2)));
char *devname(dev_t, mode_t);
+void freezero(void *, size_t);
void *reallocarray(void *, size_t, size_t);
void *recallocarray(void *, size_t, size_t, size_t);
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
diff --git a/lib/libopenbsd/stdlib/Makefile.inc b/lib/libopenbsd/stdlib/Makefile.inc
index eba477d..c71a22b 100644
--- a/lib/libopenbsd/stdlib/Makefile.inc
+++ b/lib/libopenbsd/stdlib/Makefile.inc
@@ -6,6 +6,10 @@ VPATH+= ${LIBCSRCDIR}/stdlib
SRCS+= getopt_long.c
MAN+= getopt.3 getopt_long.3
+ifneq ($(HAVE_FREEZERO),1)
+SRCS+= freezero.c
+endif
+
ifneq ($(HAVE_REALLOCARRAY),1)
SRCS+= reallocarray.c recallocarray.c
MAN+= malloc.3
diff --git a/lib/libopenbsd/stdlib/freezero.c b/lib/libopenbsd/stdlib/freezero.c
new file mode 100644
index 0000000..31face3
--- /dev/null
+++ b/lib/libopenbsd/stdlib/freezero.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
+ * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
+ * Copyright (c) 2008 Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+void
+freezero(void *ptr, size_t sz)
+{
+ /* This is legal. */
+ if (ptr == NULL)
+ return;
+
+ explicit_bzero(ptr, sz);
+ free(ptr);
+}