Skip to content

Commit

Permalink
reallocarray: avoid interposing when provided by the system
Browse files Browse the repository at this point in the history
  • Loading branch information
mathstuf authored and xaizek committed Nov 9, 2019
1 parent 9565b09 commit 4a4a429
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build-aux/config.h.in
Expand Up @@ -65,6 +65,9 @@
/* Define to 1 if you have the <mntent.h> header file. */
#undef HAVE_MNTENT_H

/* Define to 1 if you have the `reallocarray' function. */
#undef HAVE_REALLOCARRAY

/* set_escdelay() function is available. */
#undef HAVE_SET_ESCDELAY_FUNC

Expand Down
11 changes: 11 additions & 0 deletions configure
Expand Up @@ -7110,6 +7110,17 @@ else
as_fn_error $? "realloc() function not found." "$LINENO" 5
fi
for ac_func in reallocarray
do :
ac_fn_c_check_func "$LINENO" "reallocarray" "ac_cv_func_reallocarray"
if test "x$ac_cv_func_reallocarray" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_REALLOCARRAY 1
_ACEOF
fi
done
ac_fn_c_check_func "$LINENO" "realpath" "ac_cv_func_realpath"
if test "x$ac_cv_func_realpath" = xyes; then :
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -193,6 +193,7 @@ AC_CHECK_FUNC([qsort], [], [AC_MSG_ERROR([qsort() function not found.])])
AC_CHECK_FUNC([read], [], [AC_MSG_ERROR([read() function not found.])])
AC_CHECK_FUNC([readlink], [], [AC_MSG_ERROR([readlink() function not found.])])
AC_CHECK_FUNC([realloc], [], [AC_MSG_ERROR([realloc() function not found.])])
AC_CHECK_FUNCS([reallocarray])
AC_CHECK_FUNC([realpath], [], [AC_MSG_ERROR([realpath() function not found.])])
AC_CHECK_FUNC([rename], [], [AC_MSG_ERROR([rename() function not found.])])
AC_CHECK_FUNC([rmdir], [], [AC_MSG_ERROR([rmdir() function not found.])])
Expand Down
4 changes: 4 additions & 0 deletions src/compat/reallocarray.c
Expand Up @@ -14,6 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef HAVE_REALLOCARRAY

#include <sys/types.h>

#include <errno.h> /* errno EINVAL ENOMEM */
Expand Down Expand Up @@ -42,5 +44,7 @@ reallocarray(void *optr, size_t nmemb, size_t size)
return realloc(optr, size*nmemb);
}

#endif /* HAVE_REALLOCARRAY */

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
/* vim: set cinoptions+=t0 filetype=c : */
8 changes: 8 additions & 0 deletions src/compat/reallocarray.h
Expand Up @@ -19,12 +19,20 @@
#ifndef VIFM__COMPAT__REALLOCARRAY_H__
#define VIFM__COMPAT__REALLOCARRAY_H__

#ifndef HAVE_REALLOCARRAY

#include <stddef.h> /* size_t */

/* Almost the same as realloc(), but with a different way of specifying size
* and checks for integer overflow in the calculation of nmemb * size. */
void * reallocarray(void *optr, size_t nmemb, size_t size);

#else

#include <stdlib.h> /* reallocarray() */

#endif

#endif /* VIFM__COMPAT__REALLOCARRAY_H__ */

/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
Expand Down

0 comments on commit 4a4a429

Please sign in to comment.