1/* Implementation details of FILE streams. 2 Copyright (C) 2007-2010 Free Software Foundation, Inc. 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 16 17/* Many stdio implementations have the same logic and therefore can share 18 the same implementation of stdio extension API, except that some fields 19 have different naming conventions, or their access requires some casts. */ 20 21 22/* BSD stdio derived implementations. */ 23 24#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ 25 26# if defined __DragonFly__ /* DragonFly */ 27 /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */ 28# define fp_ ((struct { struct __FILE_public pub; \ 29 struct { unsigned char *_base; int _size; } _bf; \ 30 void *cookie; \ 31 void *_close; \ 32 void *_read; \ 33 void *_seek; \ 34 void *_write; \ 35 struct { unsigned char *_base; int _size; } _ub; \ 36 int _ur; \ 37 unsigned char _ubuf[3]; \ 38 unsigned char _nbuf[1]; \ 39 struct { unsigned char *_base; int _size; } _lb; \ 40 int _blksize; \ 41 fpos_t _offset; \ 42 /* More fields, not relevant here. */ \ 43 } *) fp) 44 /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */ 45# define _p pub._p 46# define _flags pub._flags 47# define _r pub._r 48# define _w pub._w 49# else 50# define fp_ fp 51# endif 52 53# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */ 54 /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> 55 and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */ 56 struct __sfileext 57 { 58 struct __sbuf _ub; /* ungetc buffer */ 59 /* More fields, not relevant here. */ 60 }; 61# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub 62# else /* FreeBSD, DragonFly, MacOS X, Cygwin */ 63# define fp_ub fp_->_ub 64# endif 65 66# define HASUB(fp) (fp_ub._base != NULL) 67 68#endif 69 70 71/* SystemV derived implementations. */ 72 73#if defined _IOERR 74 75# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */ 76# define fp_ ((struct { unsigned char *_ptr; \ 77 unsigned char *_base; \ 78 unsigned char *_end; \ 79 long _cnt; \ 80 int _file; \ 81 unsigned int _flag; \ 82 } *) fp) 83# else 84# define fp_ fp 85# endif 86 87# if defined _SCO_DS /* OpenServer */ 88# define _cnt __cnt 89# define _ptr __ptr 90# define _base __base 91# define _flag __flag 92# endif 93 94#endif 95