1/****************************************************************************
2 * Copyright 2019-2020,2021 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.30 2021/11/20 23:33:38 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
43extern "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
75struct termtype;
76extern GCC_NORETURN  NCURSES_EXPORT(void) _nc_free_tinfo(int) GCC_DEPRECATED("use exit_terminfo");
77
78#ifdef NCURSES_INTERNALS
79extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_tic(int);
80extern void _nc_leaks_dump_entry(void);
81extern NCURSES_EXPORT(void) _nc_leaks_tic(void);
82
83#if NCURSES_SP_FUNCS
84extern GCC_NORETURN NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int);
85#endif
86extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int);
87
88#else /* !NCURSES_INTERNALS */
89extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses");
90#endif
91
92#define ExitProgram(code) exit_curses(code)
93
94#else
95extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses");
96#endif /* NO_LEAKS, etc */
97
98#ifndef HAVE_NC_FREEALL
99#define HAVE_NC_FREEALL 0
100#endif
101
102#ifndef ExitProgram
103#define ExitProgram(code) exit(code)
104#endif
105
106/* doalloc.c */
107extern NCURSES_EXPORT(void *) _nc_doalloc(void *, size_t);
108#if !HAVE_STRDUP
109#undef strdup
110#define strdup _nc_strdup
111extern NCURSES_EXPORT(char *) _nc_strdup(const char *);
112#endif
113
114/* entries.c */
115extern NCURSES_EXPORT(void) _nc_leaks_tinfo(void);
116
117#define typeMalloc(type,elts) (type *)malloc((size_t)(elts)*sizeof(type))
118#define typeCalloc(type,elts) (type *)calloc((size_t)(elts),sizeof(type))
119#define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (size_t)(elts)*sizeof(type))
120
121#ifdef __cplusplus
122}
123#endif
124
125/* *INDENT-ON* */
126
127#endif /* NC_ALLOC_included */
128