Imported Upstream version 3.2.0
[debian/amanda] / gnulib / stdio-impl.h
1 /* Implementation details of FILE streams.
2    Copyright (C) 2007-2008, 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 __NetBSD__                         /* NetBSD */
25 /* Get __NetBSD_Version__.  */
26 # include <sys/param.h>
27 #endif
28
29 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
30
31 # if defined __DragonFly__          /* DragonFly */
32   /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>.  */
33 #  define fp_ ((struct { struct __FILE_public pub; \
34                          struct { unsigned char *_base; int _size; } _bf; \
35                          void *cookie; \
36                          void *_close; \
37                          void *_read; \
38                          void *_seek; \
39                          void *_write; \
40                          struct { unsigned char *_base; int _size; } _ub; \
41                          int _ur; \
42                          unsigned char _ubuf[3]; \
43                          unsigned char _nbuf[1]; \
44                          struct { unsigned char *_base; int _size; } _lb; \
45                          int _blksize; \
46                          fpos_t _offset; \
47                          /* More fields, not relevant here.  */ \
48                        } *) fp)
49   /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>.  */
50 #  define _p pub._p
51 #  define _flags pub._flags
52 #  define _r pub._r
53 #  define _w pub._w
54 # else
55 #  define fp_ fp
56 # endif
57
58 # if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ /* NetBSD >= 1.5ZA, OpenBSD */
59   /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
60      and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
61   struct __sfileext
62     {
63       struct  __sbuf _ub; /* ungetc buffer */
64       /* More fields, not relevant here.  */
65     };
66 #  define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
67 # else                                         /* FreeBSD, NetBSD <= 1.5Z, DragonFly, MacOS X, Cygwin */
68 #  define fp_ub fp_->_ub
69 # endif
70
71 # define HASUB(fp) (fp_ub._base != NULL)
72
73 #endif
74
75
76 /* SystemV derived implementations.  */
77
78 #if defined _IOERR
79
80 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
81 #  define fp_ ((struct { unsigned char *_ptr; \
82                          unsigned char *_base; \
83                          unsigned char *_end; \
84                          long _cnt; \
85                          int _file; \
86                          unsigned int _flag; \
87                        } *) fp)
88 # else
89 #  define fp_ fp
90 # endif
91
92 # if defined _SCO_DS                /* OpenServer */
93 #  define _cnt __cnt
94 #  define _ptr __ptr
95 #  define _base __base
96 #  define _flag __flag
97 # endif
98
99 #endif