xref: /freebsd/contrib/ncurses/include/nc_alloc.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /****************************************************************************
2  * Copyright 2019,2020 Thomas E. Dickey                                     *
3  * Copyright 1998-2013,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 
30 /****************************************************************************
31  *  Author: Thomas E. Dickey                    1996-on                     *
32  ****************************************************************************/
33 /* $Id: nc_alloc.h,v 1.27 2020/07/04 20:01:13 tom Exp $ */
34 
35 #ifndef NC_ALLOC_included
36 #define NC_ALLOC_included 1
37 /* *INDENT-OFF* */
38 
39 #include <ncurses_cfg.h>
40 #include <curses.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #if defined(HAVE_LIBDMALLOC) && HAVE_LIBDMALLOC
47 #include <string.h>
48 #undef strndup		/* workaround for #define in GLIBC 2.7 */
49 #include <dmalloc.h>    /* Gray Watson's library */
50 #else
51 #undef  HAVE_LIBDMALLOC
52 #define HAVE_LIBDMALLOC 0
53 #endif
54 
55 #if defined(HAVE_LIBDBMALLOC) && HAVE_LIBDBMALLOC
56 #include <dbmalloc.h>   /* Conor Cahill's library */
57 #else
58 #undef  HAVE_LIBDBMALLOC
59 #define HAVE_LIBDBMALLOC 0
60 #endif
61 
62 #if defined(HAVE_LIBMPATROL) && HAVE_LIBMPATROL
63 #include <mpatrol.h>    /* Memory-Patrol library */
64 #else
65 #undef  HAVE_LIBMPATROL
66 #define HAVE_LIBMPATROL 0
67 #endif
68 
69 #ifndef NO_LEAKS
70 #define NO_LEAKS 0
71 #endif
72 
73 #if HAVE_LIBDBMALLOC || HAVE_LIBDMALLOC || NO_LEAKS
74 #define HAVE_NC_FREEALL 1
75 struct termtype;
76 extern NCURSES_EXPORT(void) _nc_free_tinfo(int) GCC_NORETURN GCC_DEPRECATED("use exit_terminfo");
77 
78 #ifdef NCURSES_INTERNALS
79 extern NCURSES_EXPORT(void) _nc_free_tic(int) GCC_NORETURN;
80 extern NCURSES_EXPORT(void) _nc_free_tparm(void);
81 extern void _nc_leaks_dump_entry(void);
82 extern NCURSES_EXPORT(void) _nc_leaks_tic(void);
83 
84 #if NCURSES_SP_FUNCS
85 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int) GCC_NORETURN;
86 #endif
87 extern NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_NORETURN;
88 
89 #else /* !NCURSES_INTERNALS */
90 extern NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_NORETURN GCC_DEPRECATED("use exit_curses");
91 #endif
92 
93 #define ExitProgram(code) exit_curses(code)
94 
95 #else
96 extern NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_NORETURN GCC_DEPRECATED("use exit_curses");
97 #endif /* NO_LEAKS, etc */
98 
99 #ifndef HAVE_NC_FREEALL
100 #define HAVE_NC_FREEALL 0
101 #endif
102 
103 #ifndef ExitProgram
104 #define ExitProgram(code) exit(code)
105 #endif
106 
107 /* doalloc.c */
108 extern NCURSES_EXPORT(void *) _nc_doalloc(void *, size_t);
109 #if !HAVE_STRDUP
110 #undef strdup
111 #define strdup _nc_strdup
112 extern NCURSES_EXPORT(char *) _nc_strdup(const char *);
113 #endif
114 
115 /* entries.c */
116 extern NCURSES_EXPORT(void) _nc_leaks_tinfo(void);
117 
118 #define typeMalloc(type,elts) (type *)malloc((size_t)(elts)*sizeof(type))
119 #define typeCalloc(type,elts) (type *)calloc((size_t)(elts),sizeof(type))
120 #define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (size_t)(elts)*sizeof(type))
121 
122 #ifdef __cplusplus
123 }
124 #endif
125 
126 /* *INDENT-ON* */
127 
128 #endif /* NC_ALLOC_included */
129