local.h (178287) | local.h (178721) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 16 unchanged lines hidden (view full) --- 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)local.h 8.3 (Berkeley) 7/3/94 | 1/*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 16 unchanged lines hidden (view full) --- 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)local.h 8.3 (Berkeley) 7/3/94 |
33 * $FreeBSD: head/lib/libc/stdio/local.h 178287 2008-04-17 22:17:54Z jhb $ | 33 * $FreeBSD: head/lib/libc/stdio/local.h 178721 2008-05-02 15:25:07Z jhb $ |
34 */ 35 36#include <sys/types.h> /* for off_t */ 37#include <pthread.h> 38#include <string.h> 39#include <wchar.h> 40 41/* | 34 */ 35 36#include <sys/types.h> /* for off_t */ 37#include <pthread.h> 38#include <string.h> 39#include <wchar.h> 40 41/* |
42 * Information local to this implementation of stdio, 43 * in particular, macros and private variables. | 42 * Information local to this implementation of stdio, in particular, 43 * macros, private functions, private variables, and the definition of 44 * FILE. 45 * 46 * NB: to fit things in six character monocase externals, the stdio 47 * code uses the prefix `__s' for stdio objects, typically followed 48 * by a three-character attempt at a mnemonic. |
44 */ 45 | 49 */ 50 |
51/* stdio buffers */ 52struct __sbuf { 53 unsigned char *_base; 54 int _size; 55}; 56 57/* 58 * stdio state variables. 59 * 60 * The following always hold: 61 * 62 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR), 63 * _lbfsize is -_bf._size, else _lbfsize is 0 64 * if _flags&__SRD, _w is 0 65 * if _flags&__SWR, _r is 0 66 * 67 * This ensures that the getc and putc macros (or inline functions) never 68 * try to write or read from a file that is in `read' or `write' mode. 69 * (Moreover, they can, and do, automatically switch from read mode to 70 * write mode, and back, on "r+" and "w+" files.) 71 * 72 * _lbfsize is used only to make the inline line-buffered output stream 73 * code as compact as possible. 74 * 75 * _ub, _up, and _ur are used when ungetc() pushes back more characters 76 * than fit in the current _bf, or when ungetc() pushes back a character 77 * that does not match the previous one in _bf. When this happens, 78 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff 79 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r. 80 * 81 * Certain members of __sFILE are accessed directly via macros or 82 * inline functions. To preserve ABI compat, these members must not 83 * be disturbed. These members are marked below with (*). 84 */ 85struct __sFILE { 86 unsigned char *_p; /* (*) current position in (some) buffer */ 87 int _r; /* (*) read space left for getc() */ 88 int _w; /* (*) write space left for putc() */ 89 short _flags; /* (*) flags, below; this FILE is free if 0 */ 90 short _file; /* (*) fileno, if Unix descriptor, else -1 */ 91 struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ 92 int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */ 93 94 /* operations */ 95 void *_cookie; /* cookie passed to io functions */ 96 int (*_close)(void *); 97 int (*_read)(void *, char *, int); 98 fpos_t (*_seek)(void *, fpos_t, int); 99 int (*_write)(void *, const char *, int); 100 101 /* separate buffer for long sequences of ungetc() */ 102 struct __sbuf _ub; /* ungetc buffer */ 103 unsigned char *_up; /* saved _p when _p is doing ungetc data */ 104 int _ur; /* saved _r when _r is counting ungetc data */ 105 106 /* tricks to meet minimum requirements even when malloc() fails */ 107 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 108 unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 109 110 /* separate buffer for fgetln() when line crosses buffer boundary */ 111 struct __sbuf _lb; /* buffer for fgetln() */ 112 113 /* Unix stdio files get aligned to block boundaries on fseek() */ 114 int _blksize; /* stat.st_blksize (may be != _bf._size) */ 115 fpos_t _offset; /* current lseek offset */ 116 117 pthread_mutex_t _fl_mutex; /* used for MT-safety */ 118 pthread_t _fl_owner; /* current owner */ 119 int _fl_count; /* recursive lock count */ 120 int _orientation; /* orientation for fwide() */ 121 mbstate_t _mbstate; /* multibyte conversion state */ 122}; 123 124#define __SLBF 0x0001 /* line buffered */ 125#define __SNBF 0x0002 /* unbuffered */ 126#define __SRD 0x0004 /* OK to read */ 127#define __SWR 0x0008 /* OK to write */ 128 /* RD and WR are never simultaneously asserted */ 129#define __SRW 0x0010 /* open for reading & writing */ 130#define __SEOF 0x0020 /* found EOF */ 131#define __SERR 0x0040 /* found error */ 132#define __SMBF 0x0080 /* _buf is from malloc */ 133#define __SAPP 0x0100 /* fdopen()ed in append mode */ 134#define __SSTR 0x0200 /* this is an sprintf/snprintf string */ 135#define __SOPT 0x0400 /* do fseek() optimization */ 136#define __SNPT 0x0800 /* do not do fseek() optimization */ 137#define __SOFF 0x1000 /* set iff _offset is in fact correct */ 138#define __SMOD 0x2000 /* true => fgetln modified _p text */ 139#define __SALC 0x4000 /* allocate string space dynamically */ 140#define __SIGN 0x8000 /* ignore this file in _fwalk */ 141 |
|
46extern int _sread(FILE *, char *, int); 47extern int _swrite(FILE *, char const *, int); 48extern fpos_t _sseek(FILE *, fpos_t, int); 49extern int _ftello(FILE *, fpos_t *); 50extern int _fseeko(FILE *, off_t, int, int); 51extern int __fflush(FILE *fp); 52extern void __fcloseall(void); 53extern wint_t __fgetwc(FILE *); 54extern wint_t __fputwc(wchar_t, FILE *); 55extern int __sflush(FILE *); 56extern FILE *__sfp(void); 57extern int __slbexpand(FILE *, size_t); 58extern int __srefill(FILE *); 59extern int __sread(void *, char *, int); | 142extern int _sread(FILE *, char *, int); 143extern int _swrite(FILE *, char const *, int); 144extern fpos_t _sseek(FILE *, fpos_t, int); 145extern int _ftello(FILE *, fpos_t *); 146extern int _fseeko(FILE *, off_t, int, int); 147extern int __fflush(FILE *fp); 148extern void __fcloseall(void); 149extern wint_t __fgetwc(FILE *); 150extern wint_t __fputwc(wchar_t, FILE *); 151extern int __sflush(FILE *); 152extern FILE *__sfp(void); 153extern int __slbexpand(FILE *, size_t); 154extern int __srefill(FILE *); 155extern int __sread(void *, char *, int); |
156extern int __srget(FILE *); 157extern int __swbuf(int, FILE *); |
|
60extern int __swrite(void *, char const *, int); 61extern fpos_t __sseek(void *, fpos_t, int); 62extern int __sclose(void *); 63extern void __sinit(void); 64extern void _cleanup(void); 65extern void __smakebuf(FILE *); 66extern int __swhatbuf(FILE *, size_t *, int *); 67extern int _fwalk(int (*)(FILE *)); --- 8 unchanged lines hidden (view full) --- 76extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict, 77 __va_list); 78extern size_t __fread(void * __restrict buf, size_t size, size_t count, 79 FILE * __restrict fp); 80extern int __sdidinit; 81 82 83/* | 158extern int __swrite(void *, char const *, int); 159extern fpos_t __sseek(void *, fpos_t, int); 160extern int __sclose(void *); 161extern void __sinit(void); 162extern void _cleanup(void); 163extern void __smakebuf(FILE *); 164extern int __swhatbuf(FILE *, size_t *, int *); 165extern int _fwalk(int (*)(FILE *)); --- 8 unchanged lines hidden (view full) --- 174extern int __vfwscanf(FILE * __restrict, const wchar_t * __restrict, 175 __va_list); 176extern size_t __fread(void * __restrict buf, size_t size, size_t count, 177 FILE * __restrict fp); 178extern int __sdidinit; 179 180 181/* |
182 * Get and store individual characters from a file stream. 183 */ 184#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 185#if defined(__GNUC__) && defined(__STDC__) 186static __inline int 187__sputc(int _c, FILE *_p) 188{ 189 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) 190 return (*_p->_p++ = _c); 191 else 192 return (__swbuf(_c, _p)); 193} 194#else 195/* 196 * This has been tuned to generate reasonable code on the vax using pcc. 197 */ 198#define __sputc(c, p) \ 199 (--(p)->_w < 0 ? \ 200 (p)->_w >= (p)->_lbfsize ? \ 201 (*(p)->_p = (c)), *(p)->_p != '\n' ? \ 202 (int)*(p)->_p++ : \ 203 __swbuf('\n', p) : \ 204 __swbuf((int)(c), p) : \ 205 (*(p)->_p = (c), (int)*(p)->_p++)) 206#endif 207 208/* 209 * Return true if the file stream has encountered an error. 210 */ 211#define __sferror(p) (((p)->_flags & __SERR) != 0) 212 213/* |
|
84 * Prepare the given FILE for writing, and return 0 iff it 85 * can be written now. Otherwise, return EOF and set errno. 86 */ 87#define prepwrite(fp) \ 88 ((((fp)->_flags & __SWR) == 0 || \ 89 ((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \ 90 __swsetup(fp)) 91 --- 28 unchanged lines hidden --- | 214 * Prepare the given FILE for writing, and return 0 iff it 215 * can be written now. Otherwise, return EOF and set errno. 216 */ 217#define prepwrite(fp) \ 218 ((((fp)->_flags & __SWR) == 0 || \ 219 ((fp)->_bf._base == NULL && ((fp)->_flags & __SSTR) == 0)) && \ 220 __swsetup(fp)) 221 --- 28 unchanged lines hidden --- |