New private include file lib/stdio-impl.h.
[gnulib.git] / lib / stdio-impl.h
1 /* Implementation details of FILE streams.
2    Copyright (C) 2007-2008 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               /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */
25
26 # if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
27   /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
28      and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
29   struct __sfileext
30     {
31       struct  __sbuf _ub; /* ungetc buffer */
32       /* More fields, not relevant here.  */
33     };
34 #  define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
35 # else                                         /* FreeBSD, MacOS X, Cygwin */
36 #  define fp_ub fp->_ub
37 # endif
38
39 # define HASUB(fp) (fp_ub._base != NULL)
40
41 #endif
42
43
44 /* SystemV derived implementations.  */
45
46 #if defined _IOERR
47
48 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
49 #  define fp_ ((struct { unsigned char *_ptr; \
50                          unsigned char *_base; \
51                          unsigned char *_end; \
52                          long _cnt; \
53                          int _file; \
54                          unsigned int _flag; \
55                        } *) fp)
56 # else
57 #  define fp_ fp
58 # endif
59
60 # if defined _SCO_DS                /* OpenServer */
61 #  define _cnt __cnt
62 #  define _ptr __ptr
63 #  define _base __base
64 #  define _flag __flag
65 # endif
66
67 #endif