1*657871a7Schristos /* $NetBSD: mm-internal.h,v 1.1.1.3 2021/04/07 02:43:12 christos Exp $ */ 26ecf6635Schristos /* 36ecf6635Schristos * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 46ecf6635Schristos * 56ecf6635Schristos * Redistribution and use in source and binary forms, with or without 66ecf6635Schristos * modification, are permitted provided that the following conditions 76ecf6635Schristos * are met: 86ecf6635Schristos * 1. Redistributions of source code must retain the above copyright 96ecf6635Schristos * notice, this list of conditions and the following disclaimer. 106ecf6635Schristos * 2. Redistributions in binary form must reproduce the above copyright 116ecf6635Schristos * notice, this list of conditions and the following disclaimer in the 126ecf6635Schristos * documentation and/or other materials provided with the distribution. 136ecf6635Schristos * 3. The name of the author may not be used to endorse or promote products 146ecf6635Schristos * derived from this software without specific prior written permission. 156ecf6635Schristos * 166ecf6635Schristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 176ecf6635Schristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 186ecf6635Schristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 196ecf6635Schristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 206ecf6635Schristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 216ecf6635Schristos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 226ecf6635Schristos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 236ecf6635Schristos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 246ecf6635Schristos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 256ecf6635Schristos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 266ecf6635Schristos */ 27805a1ce9Schristos #ifndef MM_INTERNAL_H_INCLUDED_ 28805a1ce9Schristos #define MM_INTERNAL_H_INCLUDED_ 296ecf6635Schristos 306ecf6635Schristos #include <sys/types.h> 316ecf6635Schristos 326ecf6635Schristos #ifdef __cplusplus 336ecf6635Schristos extern "C" { 346ecf6635Schristos #endif 356ecf6635Schristos 36805a1ce9Schristos #ifndef EVENT__DISABLE_MM_REPLACEMENT 376ecf6635Schristos /* Internal use only: Memory allocation functions. We give them nice short 386ecf6635Schristos * mm_names for our own use, but make sure that the symbols have longer names 396ecf6635Schristos * so they don't conflict with other libraries (like, say, libmm). */ 40805a1ce9Schristos 41805a1ce9Schristos /** Allocate uninitialized memory. 42805a1ce9Schristos * 43805a1ce9Schristos * @return On success, return a pointer to sz newly allocated bytes. 44805a1ce9Schristos * On failure, set errno to ENOMEM and return NULL. 45805a1ce9Schristos * If the argument sz is 0, simply return NULL. 46805a1ce9Schristos */ 47*657871a7Schristos EVENT2_EXPORT_SYMBOL 486ecf6635Schristos void *event_mm_malloc_(size_t sz); 49805a1ce9Schristos 50805a1ce9Schristos /** Allocate memory initialized to zero. 51805a1ce9Schristos * 52805a1ce9Schristos * @return On success, return a pointer to (count * size) newly allocated 53805a1ce9Schristos * bytes, initialized to zero. 54805a1ce9Schristos * On failure, or if the product would result in an integer overflow, 55805a1ce9Schristos * set errno to ENOMEM and return NULL. 56805a1ce9Schristos * If either arguments are 0, simply return NULL. 57805a1ce9Schristos */ 58*657871a7Schristos EVENT2_EXPORT_SYMBOL 596ecf6635Schristos void *event_mm_calloc_(size_t count, size_t size); 60805a1ce9Schristos 61805a1ce9Schristos /** Duplicate a string. 62805a1ce9Schristos * 63805a1ce9Schristos * @return On success, return a pointer to a newly allocated duplicate 64805a1ce9Schristos * of a string. 65805a1ce9Schristos * Set errno to ENOMEM and return NULL if a memory allocation error 66805a1ce9Schristos * occurs (or would occur) in the process. 67805a1ce9Schristos * If the argument str is NULL, set errno to EINVAL and return NULL. 68805a1ce9Schristos */ 69*657871a7Schristos EVENT2_EXPORT_SYMBOL 70805a1ce9Schristos char *event_mm_strdup_(const char *str); 71805a1ce9Schristos 72*657871a7Schristos EVENT2_EXPORT_SYMBOL 736ecf6635Schristos void *event_mm_realloc_(void *p, size_t sz); 74*657871a7Schristos EVENT2_EXPORT_SYMBOL 756ecf6635Schristos void event_mm_free_(void *p); 766ecf6635Schristos #define mm_malloc(sz) event_mm_malloc_(sz) 776ecf6635Schristos #define mm_calloc(count, size) event_mm_calloc_((count), (size)) 786ecf6635Schristos #define mm_strdup(s) event_mm_strdup_(s) 796ecf6635Schristos #define mm_realloc(p, sz) event_mm_realloc_((p), (sz)) 806ecf6635Schristos #define mm_free(p) event_mm_free_(p) 816ecf6635Schristos #else 826ecf6635Schristos #define mm_malloc(sz) malloc(sz) 836ecf6635Schristos #define mm_calloc(n, sz) calloc((n), (sz)) 846ecf6635Schristos #define mm_strdup(s) strdup(s) 856ecf6635Schristos #define mm_realloc(p, sz) realloc((p), (sz)) 866ecf6635Schristos #define mm_free(p) free(p) 876ecf6635Schristos #endif 886ecf6635Schristos 896ecf6635Schristos #ifdef __cplusplus 906ecf6635Schristos } 916ecf6635Schristos #endif 926ecf6635Schristos 936ecf6635Schristos #endif 94