lobase

Linux port of OpenBSDs userland.
Log | Files | Refs | README

commit 3d10a78d84cd6497ab671465e23e5b7de8b938f2
parent 32d200ea3ef5644890fe9db306c6a4a5cead8873
Author: Duncaen <mail@duncano.de>
Date:   Thu, 25 May 2017 16:01:36 +0200

lib/libopenbsd: add freezero(3)

Diffstat:
include/stdlib.h | 1+
lib/libopenbsd/stdlib/Makefile.inc | 4++++
lib/libopenbsd/stdlib/freezero.c | 32++++++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 0 deletions(-)

diff --git 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 @@ -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 @@ -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); +}