From c47f7e2a300d9cf4a4163e29bc3329bd9508c9e5 Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Tue, 8 Aug 2017 11:22:40 +0200 Subject: [PATCH] Add new module reallocarray-gnu --- lib/reallocarray.c | 35 +++++++++++++++++++++++++++++++++++ modules/reallocarray-gnu | 24 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 lib/reallocarray.c create mode 100644 modules/reallocarray-gnu diff --git a/lib/reallocarray.c b/lib/reallocarray.c new file mode 100644 index 000000000..cbdc66626 --- /dev/null +++ b/lib/reallocarray.c @@ -0,0 +1,35 @@ +/* reallocarray() function that is glibc compatible. + + Copyright (C) 2017 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* written by Darshit Shah */ + +#include + +#include + +#include "xalloc-oversized.h" +#include "realloc.h" + +void * +reallocarray(void *ptr, size_t nmemb, size_t size) { + if (xalloc_oversized (nmemb, size)) { + errno = ENOMEM; + return NULL; + } + /* We rely on using the semantics of the GNU realloc() function here. */ + return realloc(ptr, nmemb * size); +} diff --git a/modules/reallocarray-gnu b/modules/reallocarray-gnu new file mode 100644 index 000000000..898e1ff0f --- /dev/null +++ b/modules/reallocarray-gnu @@ -0,0 +1,24 @@ +Description: +reallocarray() function that is glibc compatible. + +Files: +lib/reallocarray.c + +Depends-on: +xalloc-oversized +realloc-gnu +stdlib + +configure.ac: +gl_MODULE_INDICATOR([reallocarray-gnu]) + +Makefile.am: + +Include: + + +License: +GPL + +Maintainer: +Darshit Shah -- 2.14.0