summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac10
-rw-r--r--openbsd-compat/Makefile.in2
-rw-r--r--openbsd-compat/bsd-malloc.c55
3 files changed, 66 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 545bee88e..e9c593acb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1331,7 +1331,17 @@ AC_CHECK_FUNCS([fmt_scaled scan_scaled login logout openpty updwtmp logwtmp])
1331AC_SEARCH_LIBS([inet_ntop], [resolv nsl]) 1331AC_SEARCH_LIBS([inet_ntop], [resolv nsl])
1332AC_SEARCH_LIBS([gethostbyname], [resolv nsl]) 1332AC_SEARCH_LIBS([gethostbyname], [resolv nsl])
1333 1333
1334# "Particular Function Checks"
1335# see https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Particular-Functions.html
1334AC_FUNC_STRFTIME 1336AC_FUNC_STRFTIME
1337AC_FUNC_MALLOC
1338AC_FUNC_REALLOC
1339# autoconf doesn't have AC_FUNC_CALLOC so fake it if malloc returns NULL;
1340if test "x$ac_cv_func_malloc_0_nonnull" != "xyes"; then
1341 AC_DEFINE(HAVE_CALLOC, 0, [calloc(x, 0) returns NULL])
1342 AC_DEFINE(calloc, rpl_calloc,
1343 [Define to rpl_calloc if the replacement function should be used.])
1344fi
1335 1345
1336# Check for ALTDIRFUNC glob() extension 1346# Check for ALTDIRFUNC glob() extension
1337AC_MSG_CHECKING([for GLOB_ALTDIRFUNC support]) 1347AC_MSG_CHECKING([for GLOB_ALTDIRFUNC support])
diff --git a/openbsd-compat/Makefile.in b/openbsd-compat/Makefile.in
index 77378a464..ac8ae4305 100644
--- a/openbsd-compat/Makefile.in
+++ b/openbsd-compat/Makefile.in
@@ -18,7 +18,7 @@ LDFLAGS=-L. @LDFLAGS@
18 18
19OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o reallocarray.o realpath.o recallocarray.o rresvport.o setenv.o setproctitle.o sha1.o sha2.o rmd160.o md5.o sigact.o strcasestr.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o blowfish.o bcrypt_pbkdf.o explicit_bzero.o freezero.o 19OPENBSD=base64.o basename.o bcrypt_pbkdf.o bindresvport.o blowfish.o daemon.o dirname.o fmt_scaled.o getcwd.o getgrouplist.o getopt_long.o getrrsetbyname.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o pwcache.o readpassphrase.o reallocarray.o realpath.o recallocarray.o rresvport.o setenv.o setproctitle.o sha1.o sha2.o rmd160.o md5.o sigact.o strcasestr.o strlcat.o strlcpy.o strmode.o strnlen.o strptime.o strsep.o strtonum.o strtoll.o strtoul.o strtoull.o timingsafe_bcmp.o vis.o blowfish.o bcrypt_pbkdf.o explicit_bzero.o freezero.o
20 20
21COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-err.o bsd-getpagesize.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xcrypt.o kludge-fd_set.o 21COMPAT=arc4random.o bsd-asprintf.o bsd-closefrom.o bsd-cray.o bsd-cygwin_util.o bsd-getpeereid.o getrrsetbyname-ldns.o bsd-err.o bsd-getpagesize.o bsd-misc.o bsd-nextstep.o bsd-openpty.o bsd-poll.o bsd-malloc.o bsd-setres_id.o bsd-snprintf.o bsd-statvfs.o bsd-waitpid.o fake-rfc2553.o openssl-compat.o xcrypt.o kludge-fd_set.o
22 22
23PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o 23PORTS=port-aix.o port-irix.o port-linux.o port-solaris.o port-tun.o port-uw.o
24 24
diff --git a/openbsd-compat/bsd-malloc.c b/openbsd-compat/bsd-malloc.c
new file mode 100644
index 000000000..6402ab588
--- /dev/null
+++ b/openbsd-compat/bsd-malloc.c
@@ -0,0 +1,55 @@
1/*
2 * Copyright (c) 2017 Darren Tucker (dtucker at zip com au).
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include "config.h"
18#undef malloc
19#undef calloc
20#undef realloc
21
22#include <sys/types.h>
23#include <stdlib.h>
24
25#if defined(HAVE_MALLOC) && HAVE_MALLOC == 0
26void *
27rpl_malloc(size_t size)
28{
29 if (size == 0)
30 size = 1;
31 return malloc(size);
32}
33#endif
34
35#if defined(HAVE_CALLOC) && HAVE_CALLOC == 0
36void *
37rpl_calloc(size_t nmemb, size_t size)
38{
39 if (nmemb == 0)
40 nmemb = 1;
41 if (size == 0)
42 size = 1;
43 return calloc(nmemb, size);
44}
45#endif
46
47#if defined (HAVE_REALLOC) && HAVE_REALLOC == 0
48void *
49rpl_realloc(void *ptr, size_t size)
50{
51 if (size == 0)
52 size = 1;
53 return realloc(ptr, size);
54}
55#endif