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 2018-2022,2024 Thomas E. Dickey * |
| 3 | * Copyright 1998-2016,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: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 32 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
| 33 | * and: Thomas E. Dickey 1996-on * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 34 | * and: Juergen Pfeifer * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 35 | ****************************************************************************/ |
| 36 | |
| 37 | /* |
| 38 | ** lib_data.c |
| 39 | ** |
| 40 | ** Common data that may/may not be allocated, but is referenced globally |
| 41 | ** |
| 42 | */ |
| 43 | |
| 44 | #include <curses.priv.h> |
| 45 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 46 | MODULE_ID("$Id: lib_data.c,v 1.89 2024/02/24 18:11:38 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * OS/2's native linker complains if we don't initialize public data when |
| 50 | * constructing a dll (reported by J.J.G.Ripoll). |
| 51 | */ |
| 52 | #if USE_REENTRANT |
| 53 | NCURSES_EXPORT(WINDOW *) |
| 54 | NCURSES_PUBLIC_VAR(stdscr) (void) |
| 55 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 56 | return CURRENT_SCREEN ? StdScreen(CURRENT_SCREEN) : 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 57 | } |
| 58 | NCURSES_EXPORT(WINDOW *) |
| 59 | NCURSES_PUBLIC_VAR(curscr) (void) |
| 60 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 61 | return CURRENT_SCREEN ? CurScreen(CURRENT_SCREEN) : 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 62 | } |
| 63 | NCURSES_EXPORT(WINDOW *) |
| 64 | NCURSES_PUBLIC_VAR(newscr) (void) |
| 65 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 66 | return CURRENT_SCREEN ? NewScreen(CURRENT_SCREEN) : 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 67 | } |
| 68 | #else |
| 69 | NCURSES_EXPORT_VAR(WINDOW *) stdscr = 0; |
| 70 | NCURSES_EXPORT_VAR(WINDOW *) curscr = 0; |
| 71 | NCURSES_EXPORT_VAR(WINDOW *) newscr = 0; |
| 72 | #endif |
| 73 | |
| 74 | NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain = 0; |
| 75 | |
| 76 | /* |
| 77 | * The variable 'SP' will be defined as a function on systems that cannot link |
| 78 | * data-only modules, since it is used in a lot of places within ncurses and we |
| 79 | * cannot guarantee that any application will use any particular function. We |
| 80 | * put the WINDOW variables in this module, because it appears that any |
| 81 | * application that uses them will also use 'SP'. |
| 82 | * |
| 83 | * This module intentionally does not reference other ncurses modules, to avoid |
| 84 | * module coupling that increases the size of the executable. |
| 85 | */ |
| 86 | #if BROKEN_LINKER |
| 87 | static SCREEN *my_screen; |
| 88 | |
| 89 | NCURSES_EXPORT(SCREEN *) |
| 90 | _nc_screen(void) |
| 91 | { |
| 92 | return my_screen; |
| 93 | } |
| 94 | |
| 95 | NCURSES_EXPORT(int) |
| 96 | _nc_alloc_screen(void) |
| 97 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 98 | my_screen = _nc_alloc_screen_sp(); |
| 99 | T(("_nc_alloc_screen_sp %p", my_screen)); |
| 100 | return (my_screen != 0); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | NCURSES_EXPORT(void) |
| 104 | _nc_set_screen(SCREEN *sp) |
| 105 | { |
| 106 | my_screen = sp; |
| 107 | } |
| 108 | |
| 109 | #else |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 110 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 111 | NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data... */ |
| 112 | #endif |
| 113 | /* *INDENT-OFF* */ |
| 114 | #define CHARS_0s { '\0' } |
| 115 | |
| 116 | #define TGETENT_0 { 0L, FALSE, NULL, NULL, NULL } |
| 117 | #define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 } |
| 118 | |
| 119 | NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 120 | 0, /* have_sigtstp */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 121 | 0, /* have_sigwinch */ |
| 122 | 0, /* cleanup_nested */ |
| 123 | |
| 124 | FALSE, /* init_signals */ |
| 125 | FALSE, /* init_screen */ |
| 126 | |
| 127 | NULL, /* comp_sourcename */ |
| 128 | NULL, /* comp_termtype */ |
| 129 | |
| 130 | FALSE, /* have_tic_directory */ |
| 131 | FALSE, /* keep_tic_directory */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 132 | 0, /* tic_directory */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 133 | |
| 134 | NULL, /* dbi_list */ |
| 135 | 0, /* dbi_size */ |
| 136 | |
| 137 | NULL, /* first_name */ |
| 138 | NULL, /* keyname_table */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 139 | 0, /* init_keyname */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 140 | |
| 141 | 0, /* slk_format */ |
| 142 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 143 | 2048, /* getstr_limit */ |
| 144 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 145 | NULL, /* safeprint_buf */ |
| 146 | 0, /* safeprint_used */ |
| 147 | |
| 148 | TGETENT_0s, /* tgetent_cache */ |
| 149 | 0, /* tgetent_index */ |
| 150 | 0, /* tgetent_sequence */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 151 | 0, /* terminal_count */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 152 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 153 | 0, /* dbd_blob */ |
| 154 | 0, /* dbd_list */ |
| 155 | 0, /* dbd_size */ |
| 156 | 0, /* dbd_time */ |
| 157 | { { 0, 0 } }, /* dbd_vars */ |
| 158 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 159 | #if HAVE_TSEARCH |
| 160 | NULL, /* cached_tparm */ |
| 161 | 0, /* count_tparm */ |
| 162 | #endif /* HAVE_TSEARCH */ |
| 163 | |
| 164 | #ifdef USE_TERM_DRIVER |
| 165 | 0, /* term_driver */ |
| 166 | #endif |
| 167 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 168 | #ifndef USE_SP_WINDOWLIST |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 169 | 0, /* _nc_windowlist */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 170 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 171 | |
| 172 | #if USE_HOME_TERMINFO |
| 173 | NULL, /* home_terminfo */ |
| 174 | #endif |
| 175 | |
| 176 | #if !USE_SAFE_SPRINTF |
| 177 | 0, /* safeprint_cols */ |
| 178 | 0, /* safeprint_rows */ |
| 179 | #endif |
| 180 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 181 | #ifdef USE_PTHREADS |
| 182 | PTHREAD_MUTEX_INITIALIZER, /* mutex_curses */ |
| 183 | PTHREAD_MUTEX_INITIALIZER, /* mutex_prescreen */ |
| 184 | PTHREAD_MUTEX_INITIALIZER, /* mutex_screen */ |
| 185 | PTHREAD_MUTEX_INITIALIZER, /* mutex_update */ |
| 186 | PTHREAD_MUTEX_INITIALIZER, /* mutex_tst_tracef */ |
| 187 | PTHREAD_MUTEX_INITIALIZER, /* mutex_tracef */ |
| 188 | 0, /* nested_tracef */ |
| 189 | 0, /* use_pthreads */ |
| 190 | #if USE_PTHREADS_EINTR |
| 191 | 0, /* read_thread */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 192 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 193 | #endif |
| 194 | #if USE_WIDEC_SUPPORT |
| 195 | CHARS_0s, /* key_name */ |
| 196 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 197 | #ifdef TRACE |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 198 | FALSE, /* trace_opened */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 199 | 0, /* trace_level */ |
| 200 | NULL, /* trace_fp */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 201 | -1, /* trace_fd */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 202 | |
| 203 | NULL, /* tracearg_buf */ |
| 204 | 0, /* tracearg_used */ |
| 205 | |
| 206 | NULL, /* tracebuf_ptr */ |
| 207 | 0, /* tracebuf_used */ |
| 208 | |
| 209 | CHARS_0s, /* tracechr_buf */ |
| 210 | |
| 211 | NULL, /* tracedmp_buf */ |
| 212 | 0, /* tracedmp_used */ |
| 213 | |
| 214 | NULL, /* tracetry_buf */ |
| 215 | 0, /* tracetry_used */ |
| 216 | |
| 217 | { CHARS_0s, CHARS_0s }, /* traceatr_color_buf */ |
| 218 | 0, /* traceatr_color_sel */ |
| 219 | -1, /* traceatr_color_last */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 220 | #if !defined(USE_PTHREADS) && USE_REENTRANT |
| 221 | 0, /* nested_tracef */ |
| 222 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 223 | #endif /* TRACE */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 224 | #if NO_LEAKS |
| 225 | FALSE, /* leak_checking */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 226 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | #define STACK_FRAME_0 { { 0 }, 0 } |
| 230 | #define STACK_FRAME_0s { STACK_FRAME_0 } |
| 231 | #define NUM_VARS_0s { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } |
| 232 | |
| 233 | #define RIPOFF_0 { 0,0,0 } |
| 234 | #define RIPOFF_0s { RIPOFF_0 } |
| 235 | |
| 236 | NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 237 | NULL, /* allocated */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 238 | TRUE, /* use_env */ |
| 239 | FALSE, /* filter_mode */ |
| 240 | A_NORMAL, /* previous_attr */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 241 | { /* tparm_state */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 242 | NULL, /* tparam_base */ |
| 243 | |
| 244 | STACK_FRAME_0s, /* stack */ |
| 245 | 0, /* stack_ptr */ |
| 246 | |
| 247 | NULL, /* out_buff */ |
| 248 | 0, /* out_size */ |
| 249 | 0, /* out_used */ |
| 250 | |
| 251 | NULL, /* fmt_buff */ |
| 252 | 0, /* fmt_size */ |
| 253 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 254 | NUM_VARS_0s, /* static_vars */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 255 | #ifdef TRACE |
| 256 | NULL, /* tname */ |
| 257 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 258 | }, |
| 259 | NULL, /* saved_tty */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 260 | FALSE, /* use_tioctl */ |
| 261 | 0, /* _outch */ |
| 262 | #ifndef USE_SP_RIPOFF |
| 263 | RIPOFF_0s, /* ripoff */ |
| 264 | NULL, /* rsp */ |
| 265 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 266 | #if NCURSES_NO_PADDING |
| 267 | FALSE, /* flag to set if padding disabled */ |
| 268 | #endif |
| 269 | #if BROKEN_LINKER || USE_REENTRANT |
| 270 | NULL, /* real_acs_map */ |
| 271 | 0, /* LINES */ |
| 272 | 0, /* COLS */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 273 | 8, /* TABSIZE */ |
| 274 | 1000, /* ESCDELAY */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 275 | 0, /* cur_term */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 276 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 277 | #ifdef TRACE |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 278 | #if BROKEN_LINKER || USE_REENTRANT |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 279 | 0L, /* _outchars */ |
| 280 | NULL, /* _tputs_trace */ |
| 281 | #endif |
| 282 | #endif |
| 283 | }; |
| 284 | /* *INDENT-ON* */ |
| 285 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 286 | /* |
| 287 | * wgetch() and other functions with a WINDOW* parameter may use a SCREEN* |
| 288 | * internally, and it is useful to allow those to be invoked without switching |
| 289 | * SCREEN's, e.g., for multi-threaded applications. |
| 290 | */ |
| 291 | NCURSES_EXPORT(SCREEN *) |
| 292 | _nc_screen_of(WINDOW *win) |
| 293 | { |
| 294 | SCREEN *sp = 0; |
| 295 | |
| 296 | if (win != 0) { |
| 297 | sp = WINDOW_EXT(win, screen); |
| 298 | } |
| 299 | return (sp); |
| 300 | } |
| 301 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 302 | /******************************************************************************/ |
| 303 | #ifdef USE_PTHREADS |
| 304 | static void |
| 305 | init_global_mutexes(void) |
| 306 | { |
| 307 | static bool initialized = FALSE; |
| 308 | |
| 309 | if (!initialized) { |
| 310 | initialized = TRUE; |
| 311 | _nc_mutex_init(&_nc_globals.mutex_curses); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 312 | _nc_mutex_init(&_nc_globals.mutex_prescreen); |
| 313 | _nc_mutex_init(&_nc_globals.mutex_screen); |
| 314 | _nc_mutex_init(&_nc_globals.mutex_update); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 315 | _nc_mutex_init(&_nc_globals.mutex_tst_tracef); |
| 316 | _nc_mutex_init(&_nc_globals.mutex_tracef); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | NCURSES_EXPORT(void) |
| 321 | _nc_init_pthreads(void) |
| 322 | { |
| 323 | if (_nc_use_pthreads) |
| 324 | return; |
| 325 | # if USE_WEAK_SYMBOLS |
| 326 | if ((pthread_mutex_init) == 0) |
| 327 | return; |
| 328 | if ((pthread_mutex_lock) == 0) |
| 329 | return; |
| 330 | if ((pthread_mutex_unlock) == 0) |
| 331 | return; |
| 332 | if ((pthread_mutex_trylock) == 0) |
| 333 | return; |
| 334 | if ((pthread_mutexattr_settype) == 0) |
| 335 | return; |
| 336 | # endif |
| 337 | _nc_use_pthreads = 1; |
| 338 | init_global_mutexes(); |
| 339 | } |
| 340 | |
| 341 | /* |
| 342 | * Use recursive mutexes if we have them - they're part of Unix98. |
| 343 | * For the cases where we do not, _nc_mutex_trylock() is used to avoid a |
| 344 | * deadlock, at the expense of memory leaks and unexpected failures that |
| 345 | * may not be handled by typical clients. |
| 346 | * |
| 347 | * FIXME - need configure check for PTHREAD_MUTEX_RECURSIVE, define it to |
| 348 | * PTHREAD_MUTEX_NORMAL if not supported. |
| 349 | */ |
| 350 | NCURSES_EXPORT(void) |
| 351 | _nc_mutex_init(pthread_mutex_t * obj) |
| 352 | { |
| 353 | pthread_mutexattr_t recattr; |
| 354 | |
| 355 | if (_nc_use_pthreads) { |
| 356 | pthread_mutexattr_init(&recattr); |
| 357 | pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_RECURSIVE); |
| 358 | pthread_mutex_init(obj, &recattr); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | NCURSES_EXPORT(int) |
| 363 | _nc_mutex_lock(pthread_mutex_t * obj) |
| 364 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 365 | int rc = 0; |
| 366 | if (_nc_use_pthreads != 0) |
| 367 | rc = pthread_mutex_lock(obj); |
| 368 | return rc; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | NCURSES_EXPORT(int) |
| 372 | _nc_mutex_trylock(pthread_mutex_t * obj) |
| 373 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 374 | int rc = 0; |
| 375 | if (_nc_use_pthreads != 0) |
| 376 | rc = pthread_mutex_trylock(obj); |
| 377 | return rc; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | NCURSES_EXPORT(int) |
| 381 | _nc_mutex_unlock(pthread_mutex_t * obj) |
| 382 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 383 | int rc = 0; |
| 384 | if (_nc_use_pthreads != 0) |
| 385 | rc = pthread_mutex_unlock(obj); |
| 386 | return rc; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 387 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 388 | #endif /* USE_PTHREADS */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 389 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 390 | #if defined(USE_PTHREADS) || USE_PTHREADS_EINTR |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 391 | #if USE_WEAK_SYMBOLS |
| 392 | /* |
| 393 | * NB: sigprocmask(2) is global but pthread_sigmask(3p) |
| 394 | * only for the calling thread. |
| 395 | */ |
| 396 | NCURSES_EXPORT(int) |
| 397 | _nc_sigprocmask(int how, const sigset_t * newmask, sigset_t * oldmask) |
| 398 | { |
| 399 | if ((pthread_sigmask)) |
| 400 | return pthread_sigmask(how, newmask, oldmask); |
| 401 | else |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 402 | return (sigprocmask) (how, newmask, oldmask); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 403 | } |
| 404 | #endif |
| 405 | #endif /* USE_PTHREADS */ |