xref: /openbsd/lib/libcurses/base/use_window.c (revision c7ef0cfc)
1*c7ef0cfcSnicm /* $OpenBSD: use_window.c,v 1.2 2023/10/17 09:52:09 nicm Exp $ */
281d8c4e1Snicm 
381d8c4e1Snicm /****************************************************************************
4*c7ef0cfcSnicm  * Copyright 2018,2020 Thomas E. Dickey                                     *
5*c7ef0cfcSnicm  * Copyright 2007-2009,2016 Free Software Foundation, Inc.                  *
681d8c4e1Snicm  *                                                                          *
781d8c4e1Snicm  * Permission is hereby granted, free of charge, to any person obtaining a  *
881d8c4e1Snicm  * copy of this software and associated documentation files (the            *
981d8c4e1Snicm  * "Software"), to deal in the Software without restriction, including      *
1081d8c4e1Snicm  * without limitation the rights to use, copy, modify, merge, publish,      *
1181d8c4e1Snicm  * distribute, distribute with modifications, sublicense, and/or sell       *
1281d8c4e1Snicm  * copies of the Software, and to permit persons to whom the Software is    *
1381d8c4e1Snicm  * furnished to do so, subject to the following conditions:                 *
1481d8c4e1Snicm  *                                                                          *
1581d8c4e1Snicm  * The above copyright notice and this permission notice shall be included  *
1681d8c4e1Snicm  * in all copies or substantial portions of the Software.                   *
1781d8c4e1Snicm  *                                                                          *
1881d8c4e1Snicm  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1981d8c4e1Snicm  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
2081d8c4e1Snicm  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
2181d8c4e1Snicm  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
2281d8c4e1Snicm  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2381d8c4e1Snicm  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2481d8c4e1Snicm  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2581d8c4e1Snicm  *                                                                          *
2681d8c4e1Snicm  * Except as contained in this notice, the name(s) of the above copyright   *
2781d8c4e1Snicm  * holders shall not be used in advertising or otherwise to promote the     *
2881d8c4e1Snicm  * sale, use or other dealings in this Software without prior written       *
2981d8c4e1Snicm  * authorization.                                                           *
3081d8c4e1Snicm  ****************************************************************************/
3181d8c4e1Snicm 
3281d8c4e1Snicm /****************************************************************************
3381d8c4e1Snicm  *     Author: Thomas E. Dickey                        2007                 *
3481d8c4e1Snicm  ****************************************************************************/
3581d8c4e1Snicm 
3681d8c4e1Snicm #include <curses.priv.h>
3781d8c4e1Snicm 
38*c7ef0cfcSnicm MODULE_ID("$Id: use_window.c,v 1.2 2023/10/17 09:52:09 nicm Exp $")
3981d8c4e1Snicm 
NCURSES_EXPORT(int)4081d8c4e1Snicm NCURSES_EXPORT(int)
4181d8c4e1Snicm use_window(WINDOW *win, NCURSES_WINDOW_CB func, void *data)
4281d8c4e1Snicm {
4381d8c4e1Snicm     int code = OK;
44*c7ef0cfcSnicm     TR_FUNC_BFR(1);
4581d8c4e1Snicm 
46*c7ef0cfcSnicm     T((T_CALLED("use_window(%p,%s,%p)"),
47*c7ef0cfcSnicm        (void *) win,
48*c7ef0cfcSnicm        TR_FUNC_ARG(0, func),
49*c7ef0cfcSnicm        data));
50*c7ef0cfcSnicm 
5181d8c4e1Snicm     _nc_lock_global(curses);
5281d8c4e1Snicm     code = func(win, data);
5381d8c4e1Snicm     _nc_unlock_global(curses);
5481d8c4e1Snicm 
5581d8c4e1Snicm     returnCode(code);
5681d8c4e1Snicm }
57