xref: /openbsd-src/lib/libcurses/nc_alloc.h (revision c7ef0cfc17afcba97172c25e1e3a943e893bc632)
1*c7ef0cfcSnicm /* $OpenBSD: nc_alloc.h,v 1.8 2023/10/17 09:52:08 nicm Exp $ */
26f4099feSmillert 
304dfece0Smillert /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2019-2020,2021 Thomas E. Dickey                                *
5*c7ef0cfcSnicm  * Copyright 1998-2013,2017 Free Software Foundation, Inc.                  *
6010b00ebSmillert  *                                                                          *
704dfece0Smillert  * Permission is hereby granted, free of charge, to any person obtaining a  *
804dfece0Smillert  * copy of this software and associated documentation files (the            *
904dfece0Smillert  * "Software"), to deal in the Software without restriction, including      *
1004dfece0Smillert  * without limitation the rights to use, copy, modify, merge, publish,      *
1104dfece0Smillert  * distribute, distribute with modifications, sublicense, and/or sell       *
1204dfece0Smillert  * copies of the Software, and to permit persons to whom the Software is    *
1304dfece0Smillert  * furnished to do so, subject to the following conditions:                 *
1404dfece0Smillert  *                                                                          *
1504dfece0Smillert  * The above copyright notice and this permission notice shall be included  *
1604dfece0Smillert  * in all copies or substantial portions of the Software.                   *
1704dfece0Smillert  *                                                                          *
1804dfece0Smillert  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1904dfece0Smillert  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
2004dfece0Smillert  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
2104dfece0Smillert  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
2204dfece0Smillert  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2304dfece0Smillert  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2404dfece0Smillert  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2504dfece0Smillert  *                                                                          *
2604dfece0Smillert  * Except as contained in this notice, the name(s) of the above copyright   *
2704dfece0Smillert  * holders shall not be used in advertising or otherwise to promote the     *
2804dfece0Smillert  * sale, use or other dealings in this Software without prior written       *
2904dfece0Smillert  * authorization.                                                           *
3004dfece0Smillert  ****************************************************************************/
3104dfece0Smillert 
3204dfece0Smillert /****************************************************************************
3381d8c4e1Snicm  *  Author: Thomas E. Dickey                    1996-on                     *
3404dfece0Smillert  ****************************************************************************/
35*c7ef0cfcSnicm /* $Id: nc_alloc.h,v 1.8 2023/10/17 09:52:08 nicm Exp $ */
36010b00ebSmillert 
37010b00ebSmillert #ifndef NC_ALLOC_included
38010b00ebSmillert #define NC_ALLOC_included 1
39*c7ef0cfcSnicm /* *INDENT-OFF* */
40*c7ef0cfcSnicm 
41*c7ef0cfcSnicm #include <ncurses_cfg.h>
42*c7ef0cfcSnicm #include <curses.h>
43010b00ebSmillert 
4481d8c4e1Snicm #ifdef __cplusplus
4581d8c4e1Snicm extern "C" {
4681d8c4e1Snicm #endif
4781d8c4e1Snicm 
48*c7ef0cfcSnicm #if defined(HAVE_LIBDMALLOC) && HAVE_LIBDMALLOC
4981d8c4e1Snicm #include <string.h>
5081d8c4e1Snicm #undef strndup		/* workaround for #define in GLIBC 2.7 */
51010b00ebSmillert #include <dmalloc.h>    /* Gray Watson's library */
52010b00ebSmillert #else
53010b00ebSmillert #undef  HAVE_LIBDMALLOC
54010b00ebSmillert #define HAVE_LIBDMALLOC 0
55010b00ebSmillert #endif
56010b00ebSmillert 
57*c7ef0cfcSnicm #if defined(HAVE_LIBDBMALLOC) && HAVE_LIBDBMALLOC
58010b00ebSmillert #include <dbmalloc.h>   /* Conor Cahill's library */
59010b00ebSmillert #else
60010b00ebSmillert #undef  HAVE_LIBDBMALLOC
61010b00ebSmillert #define HAVE_LIBDBMALLOC 0
62010b00ebSmillert #endif
63010b00ebSmillert 
64*c7ef0cfcSnicm #if defined(HAVE_LIBMPATROL) && HAVE_LIBMPATROL
6581d8c4e1Snicm #include <mpatrol.h>    /* Memory-Patrol library */
6681d8c4e1Snicm #else
6781d8c4e1Snicm #undef  HAVE_LIBMPATROL
6881d8c4e1Snicm #define HAVE_LIBMPATROL 0
6981d8c4e1Snicm #endif
7081d8c4e1Snicm 
71010b00ebSmillert #ifndef NO_LEAKS
72010b00ebSmillert #define NO_LEAKS 0
73010b00ebSmillert #endif
74010b00ebSmillert 
7559c7ef32Smillert #if HAVE_LIBDBMALLOC || HAVE_LIBDMALLOC || NO_LEAKS
7659c7ef32Smillert #define HAVE_NC_FREEALL 1
77010b00ebSmillert struct termtype;
78*c7ef0cfcSnicm extern GCC_NORETURN  NCURSES_EXPORT(void) _nc_free_tinfo(int) GCC_DEPRECATED("use exit_terminfo");
79*c7ef0cfcSnicm 
80*c7ef0cfcSnicm #ifdef NCURSES_INTERNALS
81*c7ef0cfcSnicm extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_tic(int);
82*c7ef0cfcSnicm extern void _nc_leaks_dump_entry(void);
8381d8c4e1Snicm extern NCURSES_EXPORT(void) _nc_leaks_tic(void);
84*c7ef0cfcSnicm 
85*c7ef0cfcSnicm #if NCURSES_SP_FUNCS
86*c7ef0cfcSnicm extern GCC_NORETURN NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int);
87010b00ebSmillert #endif
88*c7ef0cfcSnicm extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int);
89*c7ef0cfcSnicm 
90*c7ef0cfcSnicm #else /* !NCURSES_INTERNALS */
91*c7ef0cfcSnicm extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses");
92*c7ef0cfcSnicm #endif
93*c7ef0cfcSnicm 
94*c7ef0cfcSnicm #define ExitProgram(code) exit_curses(code)
95*c7ef0cfcSnicm 
96*c7ef0cfcSnicm #else
97*c7ef0cfcSnicm extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses");
98*c7ef0cfcSnicm #endif /* NO_LEAKS, etc */
99010b00ebSmillert 
10059c7ef32Smillert #ifndef HAVE_NC_FREEALL
10159c7ef32Smillert #define HAVE_NC_FREEALL 0
10259c7ef32Smillert #endif
10359c7ef32Smillert 
104010b00ebSmillert #ifndef ExitProgram
10581d8c4e1Snicm #define ExitProgram(code) exit(code)
106010b00ebSmillert #endif
107010b00ebSmillert 
1081fe33145Smillert /* doalloc.c */
10981d8c4e1Snicm extern NCURSES_EXPORT(void *) _nc_doalloc(void *, size_t);
1101fe33145Smillert #if !HAVE_STRDUP
111*c7ef0cfcSnicm #undef strdup
1121fe33145Smillert #define strdup _nc_strdup
11381d8c4e1Snicm extern NCURSES_EXPORT(char *) _nc_strdup(const char *);
1141fe33145Smillert #endif
1151fe33145Smillert 
11681d8c4e1Snicm /* entries.c */
11781d8c4e1Snicm extern NCURSES_EXPORT(void) _nc_leaks_tinfo(void);
11881d8c4e1Snicm 
119*c7ef0cfcSnicm #define typeMalloc(type,elts) (type *)malloc((size_t)(elts)*sizeof(type))
120*c7ef0cfcSnicm #define typeCalloc(type,elts) (type *)calloc((size_t)(elts),sizeof(type))
121*c7ef0cfcSnicm #define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (size_t)(elts)*sizeof(type))
1221fe33145Smillert 
12381d8c4e1Snicm #ifdef __cplusplus
12481d8c4e1Snicm }
12581d8c4e1Snicm #endif
12681d8c4e1Snicm 
127*c7ef0cfcSnicm /* *INDENT-ON* */
128*c7ef0cfcSnicm 
129010b00ebSmillert #endif /* NC_ALLOC_included */
130