From 5a2022bad6ea3a79a27a1ff0f18e1e9b02932d4d Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 15 Jun 2020 01:37:14 +0000 Subject: Only compile compat_*.c implementations that are actually needed. That's cleaner and it is supposed to fix compiler warnings with gcc 10 reported by Wynn Wolf Arbor on discuss@. --- compat_recallocarray.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'compat_recallocarray.c') diff --git a/compat_recallocarray.c b/compat_recallocarray.c index c5fcea9f..9202934b 100644 --- a/compat_recallocarray.c +++ b/compat_recallocarray.c @@ -1,15 +1,7 @@ -#include "config.h" - -#if HAVE_RECALLOCARRAY - -int dummy; - -#else - /* $Id$ */ -/* $OpenBSD: malloc.c,v 1.225 2017/05/13 07:11:29 otto Exp $ */ +/* $OpenBSD: recallocarray.c,v 1.1 2017/03/06 18:44:21 otto Exp $ */ /* - * Copyright (c) 2017 Otto Moerbeek + * Copyright (c) 2008, 2017 Otto Moerbeek * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -23,18 +15,19 @@ int dummy; * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" #include #include -#include #include +#include #include /* * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW */ -#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) +#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) /* * Even though specified in POSIX, the PAGESIZE and PAGE_SIZE @@ -42,7 +35,7 @@ int dummy; * to avoid free() overhead for small shrinking, simply pick * an arbitrary number. */ -#define MALLOC_PAGESIZE (1UL << 12) +#define getpagesize() (1UL << 12) void * @@ -75,7 +68,7 @@ recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) if (newsize <= oldsize) { size_t d = oldsize - newsize; - if (d < oldsize / 2 && d < MALLOC_PAGESIZE) { + if (d < oldsize / 2 && d < getpagesize()) { memset((char *)ptr + newsize, 0, d); return ptr; } @@ -104,5 +97,3 @@ recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size) return newptr; } - -#endif /* !HAVE_RECALLOCARRAY */ -- cgit