1*388550b0Srillig /* $NetBSD: fileext.h,v 1.7 2022/04/19 20:32:15 rillig Exp $ */ 2a510b02eSyamt 3a510b02eSyamt /*- 4a510b02eSyamt * Copyright (c)2001 Citrus Project, 5a510b02eSyamt * All rights reserved. 6a510b02eSyamt * 7a510b02eSyamt * Redistribution and use in source and binary forms, with or without 8a510b02eSyamt * modification, are permitted provided that the following conditions 9a510b02eSyamt * are met: 10a510b02eSyamt * 1. Redistributions of source code must retain the above copyright 11a510b02eSyamt * notice, this list of conditions and the following disclaimer. 12a510b02eSyamt * 2. Redistributions in binary form must reproduce the above copyright 13a510b02eSyamt * notice, this list of conditions and the following disclaimer in the 14a510b02eSyamt * documentation and/or other materials provided with the distribution. 15a510b02eSyamt * 16a510b02eSyamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17a510b02eSyamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18a510b02eSyamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19a510b02eSyamt * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20a510b02eSyamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21a510b02eSyamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22a510b02eSyamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23a510b02eSyamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24a510b02eSyamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25a510b02eSyamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26a510b02eSyamt * SUCH DAMAGE. 27a510b02eSyamt * 28a510b02eSyamt * $Citrus$ 29a510b02eSyamt */ 30a510b02eSyamt 31a510b02eSyamt /* 32a510b02eSyamt * file extension 33a510b02eSyamt */ 34a510b02eSyamt struct __sfileext { 35a510b02eSyamt struct __sbuf _ub; /* ungetc buffer */ 36a510b02eSyamt struct wchar_io_data _wcio; /* wide char i/o status */ 3700711901Sjoerg size_t _fgetstr_len; 3800711901Sjoerg char *_fgetstr_buf; 393fdac2b8Sthorpej #ifdef _REENTRANT 403fdac2b8Sthorpej mutex_t _lock; /* Lock for FLOCKFILE/FUNLOCKFILE */ 4134c915ebSnathanw cond_t _lockcond; /* Condition variable for signalling lock releases */ 4234c915ebSnathanw thr_t _lockowner; /* The thread currently holding the lock */ 4334c915ebSnathanw int _lockcount; /* Count of recursive locks */ 44b5665a9bSnathanw int _lockinternal; /* Flag of whether the lock is held inside stdio */ 45b5665a9bSnathanw int _lockcancelstate; /* Stashed cancellation state on internal lock */ 463fdac2b8Sthorpej #endif 47a510b02eSyamt }; 48a510b02eSyamt 49a510b02eSyamt #define _EXT(fp) ((struct __sfileext *)(void *)((fp)->_ext._base)) 50a510b02eSyamt #define _UB(fp) _EXT(fp)->_ub 513fdac2b8Sthorpej #ifdef _REENTRANT 523fdac2b8Sthorpej #define _LOCK(fp) (_EXT(fp)->_lock) 5334c915ebSnathanw #define _LOCKCOND(fp) (_EXT(fp)->_lockcond) 5434c915ebSnathanw #define _LOCKOWNER(fp) (_EXT(fp)->_lockowner) 5534c915ebSnathanw #define _LOCKCOUNT(fp) (_EXT(fp)->_lockcount) 56b5665a9bSnathanw #define _LOCKINTERNAL(fp) (_EXT(fp)->_lockinternal) 57b5665a9bSnathanw #define _LOCKCANCELSTATE(fp) (_EXT(fp)->_lockcancelstate) 583fdac2b8Sthorpej #define _FILEEXT_SETUP(f, fext) do { \ 593fdac2b8Sthorpej /* LINTED */(f)->_ext._base = (unsigned char *)(fext); \ 6000711901Sjoerg (fext)->_fgetstr_len = 0; \ 6100711901Sjoerg (fext)->_fgetstr_buf = NULL; \ 6234c915ebSnathanw mutex_init(&_LOCK(f), NULL); \ 6334c915ebSnathanw cond_init(&_LOCKCOND(f), 0, NULL); \ 6434c915ebSnathanw _LOCKOWNER(f) = NULL; \ 6534c915ebSnathanw _LOCKCOUNT(f) = 0; \ 66b5665a9bSnathanw _LOCKINTERNAL(f) = 0; \ 67*388550b0Srillig } while (0) 683fdac2b8Sthorpej #else 6900711901Sjoerg #define _FILEEXT_SETUP(f, fext) do { \ 7000711901Sjoerg /* LINTED */(f)->_ext._base = (unsigned char *)(fext); \ 7100711901Sjoerg (fext)->_fgetstr_len = 0; \ 7200711901Sjoerg (fext)->_fgetstr_buf = NULL; \ 73*388550b0Srillig } while (0) 743fdac2b8Sthorpej #endif 75