mirror of
git://anongit.mindrot.org/openssh.git
synced 2024-12-25 11:22:10 +00:00
e9dede06e5
Configure assumes that if malloc(0) returns null then calloc(0,n) also does. On some old platforms (SunOS4) malloc behaves as expected (as determined by AC_FUNC_MALLOC) but calloc doesn't. Test for this at configure time and activate the replacement function if found, plus handle this case in rpl_calloc.
58 lines
1.4 KiB
C
58 lines
1.4 KiB
C
/*
|
|
* Copyright (c) 2017 Darren Tucker (dtucker at zip com au).
|
|
*
|
|
* 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 "config.h"
|
|
#undef malloc
|
|
#undef calloc
|
|
#undef realloc
|
|
|
|
#include <sys/types.h>
|
|
#include <stdlib.h>
|
|
|
|
#if defined(HAVE_MALLOC) && HAVE_MALLOC == 0
|
|
void *
|
|
rpl_malloc(size_t size)
|
|
{
|
|
if (size == 0)
|
|
size = 1;
|
|
return malloc(size);
|
|
}
|
|
#endif
|
|
|
|
#if defined(HAVE_CALLOC) && HAVE_CALLOC == 0
|
|
void *
|
|
rpl_calloc(size_t nmemb, size_t size)
|
|
{
|
|
if (nmemb == 0)
|
|
nmemb = 1;
|
|
if (size == 0)
|
|
size = 1;
|
|
return calloc(nmemb, size);
|
|
}
|
|
#endif
|
|
|
|
#if defined (HAVE_REALLOC) && HAVE_REALLOC == 0
|
|
void *
|
|
rpl_realloc(void *ptr, size_t size)
|
|
{
|
|
if (size == 0)
|
|
size = 1;
|
|
if (ptr == 0)
|
|
return malloc(size);
|
|
return realloc(ptr, size);
|
|
}
|
|
#endif
|