1*eabc0478Schristos /* $NetBSD: mm-internal.h,v 1.6 2024/08/18 20:47:21 christos Exp $ */ 28585484eSchristos 38585484eSchristos /* 48585484eSchristos * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 58585484eSchristos * 68585484eSchristos * Redistribution and use in source and binary forms, with or without 78585484eSchristos * modification, are permitted provided that the following conditions 88585484eSchristos * are met: 98585484eSchristos * 1. Redistributions of source code must retain the above copyright 108585484eSchristos * notice, this list of conditions and the following disclaimer. 118585484eSchristos * 2. Redistributions in binary form must reproduce the above copyright 128585484eSchristos * notice, this list of conditions and the following disclaimer in the 138585484eSchristos * documentation and/or other materials provided with the distribution. 148585484eSchristos * 3. The name of the author may not be used to endorse or promote products 158585484eSchristos * derived from this software without specific prior written permission. 168585484eSchristos * 178585484eSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 188585484eSchristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 198585484eSchristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 208585484eSchristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 218585484eSchristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 228585484eSchristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 238585484eSchristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 248585484eSchristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 258585484eSchristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 268585484eSchristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 278585484eSchristos */ 288585484eSchristos #ifndef MM_INTERNAL_H_INCLUDED_ 298585484eSchristos #define MM_INTERNAL_H_INCLUDED_ 308585484eSchristos 318585484eSchristos #include <sys/types.h> 328585484eSchristos 338585484eSchristos #ifdef __cplusplus 348585484eSchristos extern "C" { 358585484eSchristos #endif 368585484eSchristos 378585484eSchristos #ifndef EVENT__DISABLE_MM_REPLACEMENT 388585484eSchristos /* Internal use only: Memory allocation functions. We give them nice short 398585484eSchristos * mm_names for our own use, but make sure that the symbols have longer names 408585484eSchristos * so they don't conflict with other libraries (like, say, libmm). */ 418585484eSchristos 428585484eSchristos /** Allocate uninitialized memory. 438585484eSchristos * 448585484eSchristos * @return On success, return a pointer to sz newly allocated bytes. 458585484eSchristos * On failure, set errno to ENOMEM and return NULL. 468585484eSchristos * If the argument sz is 0, simply return NULL. 478585484eSchristos */ 48*eabc0478Schristos EVENT2_EXPORT_SYMBOL 498585484eSchristos void *event_mm_malloc_(size_t sz); 508585484eSchristos 518585484eSchristos /** Allocate memory initialized to zero. 528585484eSchristos * 538585484eSchristos * @return On success, return a pointer to (count * size) newly allocated 548585484eSchristos * bytes, initialized to zero. 558585484eSchristos * On failure, or if the product would result in an integer overflow, 568585484eSchristos * set errno to ENOMEM and return NULL. 578585484eSchristos * If either arguments are 0, simply return NULL. 588585484eSchristos */ 59*eabc0478Schristos EVENT2_EXPORT_SYMBOL 608585484eSchristos void *event_mm_calloc_(size_t count, size_t size); 618585484eSchristos 628585484eSchristos /** Duplicate a string. 638585484eSchristos * 648585484eSchristos * @return On success, return a pointer to a newly allocated duplicate 658585484eSchristos * of a string. 668585484eSchristos * Set errno to ENOMEM and return NULL if a memory allocation error 678585484eSchristos * occurs (or would occur) in the process. 688585484eSchristos * If the argument str is NULL, set errno to EINVAL and return NULL. 698585484eSchristos */ 70*eabc0478Schristos EVENT2_EXPORT_SYMBOL 718585484eSchristos char *event_mm_strdup_(const char *str); 728585484eSchristos 73*eabc0478Schristos EVENT2_EXPORT_SYMBOL 748585484eSchristos void *event_mm_realloc_(void *p, size_t sz); 75*eabc0478Schristos EVENT2_EXPORT_SYMBOL 768585484eSchristos void event_mm_free_(void *p); 778585484eSchristos #define mm_malloc(sz) event_mm_malloc_(sz) 788585484eSchristos #define mm_calloc(count, size) event_mm_calloc_((count), (size)) 798585484eSchristos #define mm_strdup(s) event_mm_strdup_(s) 808585484eSchristos #define mm_realloc(p, sz) event_mm_realloc_((p), (sz)) 818585484eSchristos #define mm_free(p) event_mm_free_(p) 828585484eSchristos #else 838585484eSchristos #define mm_malloc(sz) malloc(sz) 848585484eSchristos #define mm_calloc(n, sz) calloc((n), (sz)) 858585484eSchristos #define mm_strdup(s) strdup(s) 868585484eSchristos #define mm_realloc(p, sz) realloc((p), (sz)) 878585484eSchristos #define mm_free(p) free(p) 888585484eSchristos #endif 898585484eSchristos 908585484eSchristos #ifdef __cplusplus 918585484eSchristos } 928585484eSchristos #endif 938585484eSchristos 948585484eSchristos #endif 95