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