3 @@ -106,6 +106,8 @@ icalloc (idx_t n, idx_t s)
7 +#if GNULIB_REALLOCARRAY
9 /* ireallocarray (ptr, num, size) is like reallocarray (ptr, num, size).
10 It returns a non-NULL pointer to num * size bytes of memory.
11 Upon failure, it returns NULL with errno set. */
12 @@ -131,6 +133,8 @@ ireallocarray (void *p, idx_t n, idx_t s
13 return _gl_alloc_nomem ();
16 +#endif /* GNULIB_REALLOCARRAY */
23 @@ -51,12 +51,16 @@ ximalloc (idx_t s)
24 return nonnull (imalloc (s));
27 +#if GNULIB_REALLOCARRAY
32 return XNMALLOC (n, char);
35 +#endif /* GNULIB_REALLOCARRAY */
37 /* Change the size of an allocated block of memory P to S bytes,
38 with error checking. */
40 @@ -75,6 +79,8 @@ xirealloc (void *p, idx_t s)
41 return nonnull (irealloc (p, s));
44 +#if GNULIB_REALLOCARRAY
46 /* Change the size of an allocated block of memory P to an array of N
47 objects each of S bytes, with error checking. */
49 @@ -205,6 +211,8 @@ x2nrealloc (void *p, size_t *pn, size_t
53 +#endif /* GNULIB_REALLOCARRAY */
55 /* Grow PA, which points to an array of *PN items, and return the
56 location of the reallocated array, updating *PN to reflect its
57 new size. The new array will contain at least N_INCR_MIN more
60 @@ -129,6 +129,7 @@ char *xstrdup (char const *str)
61 # define XCALLOC(n, t) \
62 ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t))))
64 +# if GNULIB_REALLOCARRAY
66 /* Allocate an array of N objects, each with S bytes of memory,
67 dynamically, with error checking. S must be nonzero. */
68 @@ -156,6 +157,8 @@ char *xcharalloc (size_t n)
69 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE
70 _GL_ATTRIBUTE_ALLOC_SIZE ((1)) _GL_ATTRIBUTE_RETURNS_NONNULL;
72 +# endif /* GNULIB_REALLOCARRAY */
74 #endif /* GNULIB_XALLOC */
77 --- a/lib/safe-alloc.h
78 +++ b/lib/safe-alloc.h
79 @@ -36,6 +36,8 @@ _GL_INLINE_HEADER_BEGIN
80 # define SAFE_ALLOC_INLINE _GL_INLINE
83 +#if GNULIB_REALLOCARRAY
85 /* Don't call these directly - use the macros below. */
86 SAFE_ALLOC_INLINE void *
87 safe_alloc_realloc_n (void *ptr, size_t count, size_t size)
88 @@ -51,6 +53,9 @@ safe_alloc_realloc_n (void *ptr, size_t
93 +#endif /* GNULIB_REALLOCARRAY */
95 _GL_ATTRIBUTE_NODISCARD SAFE_ALLOC_INLINE int
96 safe_alloc_check (void *ptr)
98 @@ -84,6 +89,8 @@ safe_alloc_check (void *ptr)
99 #define ALLOC_N(ptr, count) \
100 safe_alloc_check ((ptr) = calloc (count, sizeof *(ptr)))
102 +#if GNULIB_REALLOCARRAY
105 * ALLOC_N_UNINITIALIZED:
106 * @ptr: pointer to allocated memory
107 @@ -112,6 +119,8 @@ safe_alloc_check (void *ptr)
108 #define REALLOC_N(ptr, count) \
109 safe_alloc_check ((ptr) = safe_alloc_realloc_n (ptr, count, sizeof *(ptr)))
111 +#endif /* GNULIB_REALLOCARRAY */
115 * @ptr: pointer holding address to be freed