local.h revision 73254
1227825Stheraven/*- 2227825Stheraven * Copyright (c) 1990, 1993 3227825Stheraven * The Regents of the University of California. All rights reserved. 4227825Stheraven * 5227825Stheraven * This code is derived from software contributed to Berkeley by 6227825Stheraven * Chris Torek. 7227825Stheraven * 8227825Stheraven * Redistribution and use in source and binary forms, with or without 9227825Stheraven * modification, are permitted provided that the following conditions 10227825Stheraven * are met: 11227825Stheraven * 1. Redistributions of source code must retain the above copyright 12227825Stheraven * notice, this list of conditions and the following disclaimer. 13227825Stheraven * 2. Redistributions in binary form must reproduce the above copyright 14227825Stheraven * notice, this list of conditions and the following disclaimer in the 15227825Stheraven * documentation and/or other materials provided with the distribution. 16227825Stheraven * 3. All advertising materials mentioning features or use of this software 17227825Stheraven * must display the following acknowledgement: 18227825Stheraven * This product includes software developed by the University of 19227825Stheraven * California, Berkeley and its contributors. 20227825Stheraven * 4. Neither the name of the University nor the names of its contributors 21227825Stheraven * may be used to endorse or promote products derived from this software 22227825Stheraven * without specific prior written permission. 23227825Stheraven * 24227825Stheraven * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25227825Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26227825Stheraven * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27227825Stheraven * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28227825Stheraven * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29227825Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30227825Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31227825Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32227825Stheraven * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33227825Stheraven * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34227825Stheraven * SUCH DAMAGE. 35227825Stheraven * 36227825Stheraven * @(#)local.h 8.3 (Berkeley) 7/3/94 37227825Stheraven * 38227825Stheraven * $FreeBSD: head/lib/libc/stdio/local.h 73254 2001-03-01 05:22:14Z deischen $ 39227825Stheraven */ 40227825Stheraven 41227825Stheraven#include <sys/types.h> /* for off_t */ 42227825Stheraven#include <pthread.h> 43227825Stheraven 44227825Stheraven/* 45227825Stheraven * Information local to this implementation of stdio, 46227825Stheraven * in particular, macros and private variables. 47227825Stheraven */ 48227825Stheraven 49227825Stheravenextern int _fseeko __P((FILE *, off_t, int)); 50227825Stheravenextern int __fflush __P((FILE *fp)); 51227825Stheravenextern int __sflush __P((FILE *)); 52227825Stheravenextern FILE *__sfp __P((void)); 53227825Stheravenextern int __srefill __P((FILE *)); 54227825Stheravenextern int __sread __P((void *, char *, int)); 55227825Stheravenextern int __swrite __P((void *, char const *, int)); 56227825Stheravenextern fpos_t __sseek __P((void *, fpos_t, int)); 57227825Stheravenextern int __sclose __P((void *)); 58227825Stheravenextern void __sinit __P((void)); 59227825Stheravenextern void _cleanup __P((void)); 60227825Stheravenextern void (*__cleanup) __P((void)); 61227825Stheravenextern void __smakebuf __P((FILE *)); 62227825Stheravenextern int __swhatbuf __P((FILE *, size_t *, int *)); 63227825Stheravenextern int _fwalk __P((int (*)(FILE *))); 64227825Stheravenextern int __swsetup __P((FILE *)); 65227825Stheravenextern int __sflags __P((const char *, int *)); 66227825Stheravenextern int __ungetc __P((int, FILE *)); 67227825Stheravenextern int __vfprintf __P((FILE *, const char *, _BSD_VA_LIST_)); 68227825Stheraven 69227825Stheravenextern int __sdidinit; 70227825Stheraven 71227825Stheraven 72227825Stheraven/* hold a buncha junk that would grow the ABI */ 73232950Stheravenstruct __sFILEX { 74232950Stheraven unsigned char *_up; /* saved _p when _p is doing ungetc data */ 75227825Stheraven pthread_mutex_t fl_mutex; /* used for MT-safety */ 76227825Stheraven pthread_t fl_owner; /* current owner */ 77227825Stheraven int fl_count; /* recursive lock count */ 78227825Stheraven}; 79227825Stheraven 80227825Stheraven/* 81227825Stheraven * Return true iff the given FILE cannot be written now. 82227825Stheraven */ 83227825Stheraven#define cantwrite(fp) \ 84227825Stheraven ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ 85227825Stheraven __swsetup(fp)) 86227825Stheraven 87227825Stheraven/* 88227825Stheraven * Test whether the given stdio file has an active ungetc buffer; 89227825Stheraven * release such a buffer, without restoring ordinary unread data. 90227825Stheraven */ 91227825Stheraven#define HASUB(fp) ((fp)->_ub._base != NULL) 92227825Stheraven#define FREEUB(fp) { \ 93227825Stheraven if ((fp)->_ub._base != (fp)->_ubuf) \ 94227825Stheraven free((char *)(fp)->_ub._base); \ 95227825Stheraven (fp)->_ub._base = NULL; \ 96227825Stheraven} 97227825Stheraven 98227825Stheraven/* 99227825Stheraven * test for an fgetln() buffer. 100227825Stheraven */ 101227825Stheraven#define HASLB(fp) ((fp)->_lb._base != NULL) 102227825Stheraven#define FREELB(fp) { \ 103227825Stheraven free((char *)(fp)->_lb._base); \ 104227825Stheraven (fp)->_lb._base = NULL; \ 105227825Stheraven} 106227825Stheraven