Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2019-2020,2021 Thomas E. Dickey * |
| 3 | * Copyright 1998-2013,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | ****************************************************************************/ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 33 | /* $Id: nc_alloc.h,v 1.30 2021/11/20 23:33:38 tom Exp $ */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 34 | |
| 35 | #ifndef NC_ALLOC_included |
| 36 | #define NC_ALLOC_included 1 |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 37 | /* *INDENT-OFF* */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 38 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 39 | #include <ncurses_cfg.h> |
| 40 | #include <curses.h> |
| 41 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif |
| 45 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 46 | #if defined(HAVE_LIBDMALLOC) && HAVE_LIBDMALLOC |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 55 | #if defined(HAVE_LIBDBMALLOC) && HAVE_LIBDBMALLOC |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 56 | #include <dbmalloc.h> /* Conor Cahill's library */ |
| 57 | #else |
| 58 | #undef HAVE_LIBDBMALLOC |
| 59 | #define HAVE_LIBDBMALLOC 0 |
| 60 | #endif |
| 61 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 62 | #if defined(HAVE_LIBMPATROL) && HAVE_LIBMPATROL |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 76 | extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_tinfo(int) GCC_DEPRECATED("use exit_terminfo"); |
| 77 | |
| 78 | #ifdef NCURSES_INTERNALS |
| 79 | extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_tic(int); |
| 80 | extern void _nc_leaks_dump_entry(void); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 81 | extern NCURSES_EXPORT(void) _nc_leaks_tic(void); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 82 | |
| 83 | #if NCURSES_SP_FUNCS |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 84 | extern GCC_NORETURN NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int); |
| 85 | #endif |
| 86 | extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int); |
| 87 | |
| 88 | #else /* !NCURSES_INTERNALS */ |
| 89 | extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses"); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 90 | #endif |
| 91 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 92 | #define ExitProgram(code) exit_curses(code) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 93 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 94 | #else |
| 95 | extern GCC_NORETURN NCURSES_EXPORT(void) _nc_free_and_exit(int) GCC_DEPRECATED("use exit_curses"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 96 | #endif /* NO_LEAKS, etc */ |
| 97 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 */ |
| 107 | extern NCURSES_EXPORT(void *) _nc_doalloc(void *, size_t); |
| 108 | #if !HAVE_STRDUP |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 109 | #undef strdup |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 110 | #define strdup _nc_strdup |
| 111 | extern NCURSES_EXPORT(char *) _nc_strdup(const char *); |
| 112 | #endif |
| 113 | |
| 114 | /* entries.c */ |
| 115 | extern NCURSES_EXPORT(void) _nc_leaks_tinfo(void); |
| 116 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 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)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | |
| 121 | #ifdef __cplusplus |
| 122 | } |
| 123 | #endif |
| 124 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 125 | /* *INDENT-ON* */ |
| 126 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 127 | #endif /* NC_ALLOC_included */ |