1258a0ebeSmrg/* 25efbdfc3Smrg * Copyright (c) 2015, Oracle and/or its affiliates. 3258a0ebeSmrg * 4258a0ebeSmrg * Permission is hereby granted, free of charge, to any person obtaining a 5258a0ebeSmrg * copy of this software and associated documentation files (the "Software"), 6258a0ebeSmrg * to deal in the Software without restriction, including without limitation 7258a0ebeSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8258a0ebeSmrg * and/or sell copies of the Software, and to permit persons to whom the 9258a0ebeSmrg * Software is furnished to do so, subject to the following conditions: 10258a0ebeSmrg * 11258a0ebeSmrg * The above copyright notice and this permission notice (including the next 12258a0ebeSmrg * paragraph) shall be included in all copies or substantial portions of the 13258a0ebeSmrg * Software. 14258a0ebeSmrg * 15258a0ebeSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16258a0ebeSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17258a0ebeSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18258a0ebeSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19258a0ebeSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20258a0ebeSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21258a0ebeSmrg * DEALINGS IN THE SOFTWARE. 22258a0ebeSmrg */ 23258a0ebeSmrg 24258a0ebeSmrg#ifdef HAVE_CONFIG_H 25258a0ebeSmrg#include <config.h> 26258a0ebeSmrg#endif 27258a0ebeSmrg 28258a0ebeSmrg#include <sys/types.h> 29258a0ebeSmrg#include <stdlib.h> 30258a0ebeSmrg#include <X11/Xfuncproto.h> 31258a0ebeSmrg 32258a0ebeSmrg#ifndef HAVE_REALLOCARRAY 33258a0ebeSmrgextern _X_HIDDEN void *xreallocarray(void *optr, size_t nmemb, size_t size); 349c019ec5Smaya# define reallocarray(ptr, n, size) xreallocarray((ptr), (size_t)(n), (size_t)(size)) 35258a0ebeSmrg#endif 36258a0ebeSmrg 37258a0ebeSmrg#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__) 38258a0ebeSmrg# define Xreallocarray(ptr, n, size) \ 39258a0ebeSmrg reallocarray((ptr), ((n) == 0 ? 1 : (n)), size) 40258a0ebeSmrg#else 41258a0ebeSmrg# define Xreallocarray(ptr, n, size) reallocarray((ptr), (n), (size)) 42258a0ebeSmrg#endif 43258a0ebeSmrg 44258a0ebeSmrg#define Xmallocarray(n, size) Xreallocarray(NULL, (n), (size)) 45