blob: cfea2beb6daffd7dc168f454b41fd0d6f878f4c8 [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301/****************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002 * Copyright 2019-2020,2021 Thomas E. Dickey *
3 * Copyright 1998-2013,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304 * *
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 ****************************************************************************/
micky3879b9f5e72025-07-08 18:04:53 -040033/* $Id: nc_alloc.h,v 1.30 2021/11/20 23:33:38 tom Exp $ */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053034
35#ifndef NC_ALLOC_included
36#define NC_ALLOC_included 1
Steve Kondikae271bc2015-11-15 02:50:53 +010037/* *INDENT-OFF* */
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053038
micky3879b9f5e72025-07-08 18:04:53 -040039#include <ncurses_cfg.h>
40#include <curses.h>
41
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053042#ifdef __cplusplus
43extern "C" {
44#endif
45
Steve Kondikae271bc2015-11-15 02:50:53 +010046#if defined(HAVE_LIBDMALLOC) && HAVE_LIBDMALLOC
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047#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
Steve Kondikae271bc2015-11-15 02:50:53 +010055#if defined(HAVE_LIBDBMALLOC) && HAVE_LIBDBMALLOC
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053056#include <dbmalloc.h> /* Conor Cahill's library */
57#else
58#undef HAVE_LIBDBMALLOC
59#define HAVE_LIBDBMALLOC 0
60#endif
61
Steve Kondikae271bc2015-11-15 02:50:53 +010062#if defined(HAVE_LIBMPATROL) && HAVE_LIBMPATROL
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053063#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;
micky3879b9f5e72025-07-08 18:04:53 -040076extern 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);
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053081extern NCURSES_EXPORT(void) _nc_leaks_tic(void);
Steve Kondikae271bc2015-11-15 02:50:53 +010082
83#if NCURSES_SP_FUNCS
micky3879b9f5e72025-07-08 18:04:53 -040084extern 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");
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053090#endif
91
micky3879b9f5e72025-07-08 18:04:53 -040092#define ExitProgram(code) exit_curses(code)
Steve Kondikae271bc2015-11-15 02:50:53 +010093
micky3879b9f5e72025-07-08 18:04:53 -040094#else
95extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses");
Steve Kondikae271bc2015-11-15 02:50:53 +010096#endif /* NO_LEAKS, etc */
97
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053098#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
Steve Kondikae271bc2015-11-15 02:50:53 +0100109#undef strdup
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530110#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
Steve Kondikae271bc2015-11-15 02:50:53 +0100117#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))
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530120
121#ifdef __cplusplus
122}
123#endif
124
Steve Kondikae271bc2015-11-15 02:50:53 +0100125/* *INDENT-ON* */
126
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530127#endif /* NC_ALLOC_included */