libc_compat.h 453 B

1234567891011121314151617181920
  1. // SPDX-License-Identifier: (LGPL-2.0+ OR BSD-2-Clause)
  2. /* Copyright (C) 2018 Netronome Systems, Inc. */
  3. #ifndef __TOOLS_LIBC_COMPAT_H
  4. #define __TOOLS_LIBC_COMPAT_H
  5. #include <stdlib.h>
  6. #include <linux/overflow.h>
  7. #ifdef COMPAT_NEED_REALLOCARRAY
  8. static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
  9. {
  10. size_t bytes;
  11. if (unlikely(check_mul_overflow(nmemb, size, &bytes)))
  12. return NULL;
  13. return realloc(ptr, bytes);
  14. }
  15. #endif
  16. #endif