diff options
author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2023-03-01 14:41:23 -0300 |
---|---|---|
committer | Andreas K. Hüttel <dilfridge@gentoo.org> | 2025-01-28 21:14:01 +0100 |
commit | d0789668ddcf204fbec7493c367e2e4a090b401a (patch) | |
tree | 3d1606000ee456fcb043479ffb20a793b9727b2d | |
parent | linux: Use getdents64 on non-LFS readdir (diff) | |
download | glibc-d0789668ddcf204fbec7493c367e2e4a090b401a.tar.gz glibc-d0789668ddcf204fbec7493c367e2e4a090b401a.tar.bz2 glibc-d0789668ddcf204fbec7493c367e2e4a090b401a.zip |
support: Add xreallocarray
As a wrapper over reallocarray.
-rw-r--r-- | support/Makefile | 1 | ||||
-rw-r--r-- | support/support.h | 2 | ||||
-rw-r--r-- | support/xreallocarray.c | 29 |
3 files changed, 32 insertions, 0 deletions
diff --git a/support/Makefile b/support/Makefile index 59a9974539..cb524e2f43 100644 --- a/support/Makefile +++ b/support/Makefile @@ -210,6 +210,7 @@ libsupport-routines = \ xread \ xreadlink \ xrealloc \ + xreallocarray \ xrecvfrom \ xsendto \ xsetlocale \ diff --git a/support/support.h b/support/support.h index 4998a34894..c1b7070b1c 100644 --- a/support/support.h +++ b/support/support.h @@ -107,6 +107,8 @@ extern void *xcalloc (size_t n, size_t s) __returns_nonnull; extern void *xrealloc (void *o, size_t n) __attribute_malloc__ __attribute_alloc_size__ ((2)) __attr_dealloc_free; +extern void *xreallocarray (void *p, size_t n, size_t s) + __attribute_alloc_size__ ((2, 3)) __attr_dealloc_free; extern char *xstrdup (const char *) __attribute_malloc__ __attr_dealloc_free __returns_nonnull; void *xposix_memalign (size_t alignment, size_t n) diff --git a/support/xreallocarray.c b/support/xreallocarray.c new file mode 100644 index 0000000000..74fdaa421b --- /dev/null +++ b/support/xreallocarray.c @@ -0,0 +1,29 @@ +/* Error-checking wrapper for reallocarray + Copyright (C) 2016-2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <stdlib.h> +#include <support/support.h> + +void * +xreallocarray (void *p, size_t n, size_t s) +{ + void *r = reallocarray (p, n, s); + if (r == NULL && (p == NULL || (n != 0 && s != 0))) + oom_error ("reallocarray", n); + return r; +} |