]> asedeno.scripts.mit.edu Git - linux.git/blob - tools/include/tools/libc_compat.h
664ced8cb1b041918b3c06a3df58a3940aa640e1
[linux.git] / tools / include / tools / libc_compat.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Copyright (C) 2018 Netronome Systems, Inc. */
3
4 #ifndef __TOOLS_LIBC_COMPAT_H
5 #define __TOOLS_LIBC_COMPAT_H
6
7 #include <stdlib.h>
8 #include <linux/overflow.h>
9
10 #ifdef COMPAT_NEED_REALLOCARRAY
11 static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
12 {
13         size_t bytes;
14
15         if (unlikely(check_mul_overflow(nmemb, size, &bytes)))
16                 return NULL;
17         return realloc(ptr, bytes);
18 }
19 #endif
20 #endif