12a53b785Smrg/* 2da2777aaSmrg * Copyright (c) 2015, Oracle and/or its affiliates. 32a53b785Smrg * 42a53b785Smrg * Permission is hereby granted, free of charge, to any person obtaining a 52a53b785Smrg * copy of this software and associated documentation files (the "Software"), 62a53b785Smrg * to deal in the Software without restriction, including without limitation 72a53b785Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 82a53b785Smrg * and/or sell copies of the Software, and to permit persons to whom the 92a53b785Smrg * Software is furnished to do so, subject to the following conditions: 102a53b785Smrg * 112a53b785Smrg * The above copyright notice and this permission notice (including the next 122a53b785Smrg * paragraph) shall be included in all copies or substantial portions of the 132a53b785Smrg * Software. 142a53b785Smrg * 152a53b785Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 162a53b785Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 172a53b785Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 182a53b785Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 192a53b785Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 202a53b785Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 212a53b785Smrg * DEALINGS IN THE SOFTWARE. 222a53b785Smrg */ 232a53b785Smrg 242a53b785Smrg#ifdef HAVE_CONFIG_H 252a53b785Smrg#include <config.h> 262a53b785Smrg#endif 272a53b785Smrg 282a53b785Smrg#include <sys/types.h> 292a53b785Smrg#include <stdlib.h> 302a53b785Smrg#include <X11/Xfuncproto.h> 312a53b785Smrg 322a53b785Smrg#ifndef HAVE_REALLOCARRAY 332a53b785Smrgextern _X_HIDDEN void *xreallocarray(void *optr, size_t nmemb, size_t size); 342a53b785Smrg# define reallocarray(ptr, n, size) xreallocarray((ptr), (size_t)(n), (size_t)(size)) 352a53b785Smrg#endif 362a53b785Smrg 372a53b785Smrg#if defined(MALLOC_0_RETURNS_NULL) || defined(__clang_analyzer__) 382a53b785Smrg# define Xreallocarray(ptr, n, size) \ 392a53b785Smrg reallocarray((ptr), ((n) == 0 ? 1 : (n)), size) 402a53b785Smrg#else 412a53b785Smrg# define Xreallocarray(ptr, n, size) reallocarray((ptr), (n), (size)) 422a53b785Smrg#endif 432a53b785Smrg 442a53b785Smrg#define Xmallocarray(n, size) Xreallocarray(NULL, (n), (size)) 45