xref: /aosp_15_r20/external/libevent/mm-internal.h (revision 663afb9b963571284e0f0a60f257164ab54f64bf)
1*663afb9bSAndroid Build Coastguard Worker /*
2*663afb9bSAndroid Build Coastguard Worker  * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
3*663afb9bSAndroid Build Coastguard Worker  *
4*663afb9bSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
5*663afb9bSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
6*663afb9bSAndroid Build Coastguard Worker  * are met:
7*663afb9bSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
8*663afb9bSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
9*663afb9bSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
10*663afb9bSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
11*663afb9bSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
12*663afb9bSAndroid Build Coastguard Worker  * 3. The name of the author may not be used to endorse or promote products
13*663afb9bSAndroid Build Coastguard Worker  *    derived from this software without specific prior written permission.
14*663afb9bSAndroid Build Coastguard Worker  *
15*663afb9bSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*663afb9bSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*663afb9bSAndroid Build Coastguard Worker  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*663afb9bSAndroid Build Coastguard Worker  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*663afb9bSAndroid Build Coastguard Worker  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*663afb9bSAndroid Build Coastguard Worker  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*663afb9bSAndroid Build Coastguard Worker  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*663afb9bSAndroid Build Coastguard Worker  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*663afb9bSAndroid Build Coastguard Worker  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*663afb9bSAndroid Build Coastguard Worker  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*663afb9bSAndroid Build Coastguard Worker  */
26*663afb9bSAndroid Build Coastguard Worker #ifndef MM_INTERNAL_H_INCLUDED_
27*663afb9bSAndroid Build Coastguard Worker #define MM_INTERNAL_H_INCLUDED_
28*663afb9bSAndroid Build Coastguard Worker 
29*663afb9bSAndroid Build Coastguard Worker #include <sys/types.h>
30*663afb9bSAndroid Build Coastguard Worker 
31*663afb9bSAndroid Build Coastguard Worker #ifdef __cplusplus
32*663afb9bSAndroid Build Coastguard Worker extern "C" {
33*663afb9bSAndroid Build Coastguard Worker #endif
34*663afb9bSAndroid Build Coastguard Worker 
35*663afb9bSAndroid Build Coastguard Worker #ifndef EVENT__DISABLE_MM_REPLACEMENT
36*663afb9bSAndroid Build Coastguard Worker /* Internal use only: Memory allocation functions. We give them nice short
37*663afb9bSAndroid Build Coastguard Worker  * mm_names for our own use, but make sure that the symbols have longer names
38*663afb9bSAndroid Build Coastguard Worker  * so they don't conflict with other libraries (like, say, libmm). */
39*663afb9bSAndroid Build Coastguard Worker 
40*663afb9bSAndroid Build Coastguard Worker /** Allocate uninitialized memory.
41*663afb9bSAndroid Build Coastguard Worker  *
42*663afb9bSAndroid Build Coastguard Worker  * @return On success, return a pointer to sz newly allocated bytes.
43*663afb9bSAndroid Build Coastguard Worker  *     On failure, set errno to ENOMEM and return NULL.
44*663afb9bSAndroid Build Coastguard Worker  *     If the argument sz is 0, simply return NULL.
45*663afb9bSAndroid Build Coastguard Worker  */
46*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
47*663afb9bSAndroid Build Coastguard Worker void *event_mm_malloc_(size_t sz);
48*663afb9bSAndroid Build Coastguard Worker 
49*663afb9bSAndroid Build Coastguard Worker /** Allocate memory initialized to zero.
50*663afb9bSAndroid Build Coastguard Worker  *
51*663afb9bSAndroid Build Coastguard Worker  * @return On success, return a pointer to (count * size) newly allocated
52*663afb9bSAndroid Build Coastguard Worker  *     bytes, initialized to zero.
53*663afb9bSAndroid Build Coastguard Worker  *     On failure, or if the product would result in an integer overflow,
54*663afb9bSAndroid Build Coastguard Worker  *     set errno to ENOMEM and return NULL.
55*663afb9bSAndroid Build Coastguard Worker  *     If either arguments are 0, simply return NULL.
56*663afb9bSAndroid Build Coastguard Worker  */
57*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
58*663afb9bSAndroid Build Coastguard Worker void *event_mm_calloc_(size_t count, size_t size);
59*663afb9bSAndroid Build Coastguard Worker 
60*663afb9bSAndroid Build Coastguard Worker /** Duplicate a string.
61*663afb9bSAndroid Build Coastguard Worker  *
62*663afb9bSAndroid Build Coastguard Worker  * @return On success, return a pointer to a newly allocated duplicate
63*663afb9bSAndroid Build Coastguard Worker  *     of a string.
64*663afb9bSAndroid Build Coastguard Worker  *     Set errno to ENOMEM and return NULL if a memory allocation error
65*663afb9bSAndroid Build Coastguard Worker  *     occurs (or would occur) in the process.
66*663afb9bSAndroid Build Coastguard Worker  *     If the argument str is NULL, set errno to EINVAL and return NULL.
67*663afb9bSAndroid Build Coastguard Worker  */
68*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
69*663afb9bSAndroid Build Coastguard Worker char *event_mm_strdup_(const char *str);
70*663afb9bSAndroid Build Coastguard Worker 
71*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
72*663afb9bSAndroid Build Coastguard Worker void *event_mm_realloc_(void *p, size_t sz);
73*663afb9bSAndroid Build Coastguard Worker EVENT2_EXPORT_SYMBOL
74*663afb9bSAndroid Build Coastguard Worker void event_mm_free_(void *p);
75*663afb9bSAndroid Build Coastguard Worker #define mm_malloc(sz) event_mm_malloc_(sz)
76*663afb9bSAndroid Build Coastguard Worker #define mm_calloc(count, size) event_mm_calloc_((count), (size))
77*663afb9bSAndroid Build Coastguard Worker #define mm_strdup(s) event_mm_strdup_(s)
78*663afb9bSAndroid Build Coastguard Worker #define mm_realloc(p, sz) event_mm_realloc_((p), (sz))
79*663afb9bSAndroid Build Coastguard Worker #define mm_free(p) event_mm_free_(p)
80*663afb9bSAndroid Build Coastguard Worker #else
81*663afb9bSAndroid Build Coastguard Worker #define mm_malloc(sz) malloc(sz)
82*663afb9bSAndroid Build Coastguard Worker #define mm_calloc(n, sz) calloc((n), (sz))
83*663afb9bSAndroid Build Coastguard Worker #define mm_strdup(s) strdup(s)
84*663afb9bSAndroid Build Coastguard Worker #define mm_realloc(p, sz) realloc((p), (sz))
85*663afb9bSAndroid Build Coastguard Worker #define mm_free(p) free(p)
86*663afb9bSAndroid Build Coastguard Worker #endif
87*663afb9bSAndroid Build Coastguard Worker 
88*663afb9bSAndroid Build Coastguard Worker #ifdef __cplusplus
89*663afb9bSAndroid Build Coastguard Worker }
90*663afb9bSAndroid Build Coastguard Worker #endif
91*663afb9bSAndroid Build Coastguard Worker 
92*663afb9bSAndroid Build Coastguard Worker #endif
93