Import upstream version 1.28
[debian/tar] / gnu / stdio-impl.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Implementation details of FILE streams.
4    Copyright (C) 2007-2008, 2010-2014 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* Many stdio implementations have the same logic and therefore can share
20    the same implementation of stdio extension API, except that some fields
21    have different naming conventions, or their access requires some casts.  */
22
23
24 /* BSD stdio derived implementations.  */
25
26 #if defined __NetBSD__                         /* NetBSD */
27 /* Get __NetBSD_Version__.  */
28 # include <sys/param.h>
29 #endif
30
31 #include <errno.h>                             /* For detecting Plan9.  */
32
33 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
34
35 # if defined __DragonFly__          /* DragonFly */
36   /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>.  */
37 #  define fp_ ((struct { struct __FILE_public pub; \
38                          struct { unsigned char *_base; int _size; } _bf; \
39                          void *cookie; \
40                          void *_close; \
41                          void *_read; \
42                          void *_seek; \
43                          void *_write; \
44                          struct { unsigned char *_base; int _size; } _ub; \
45                          int _ur; \
46                          unsigned char _ubuf[3]; \
47                          unsigned char _nbuf[1]; \
48                          struct { unsigned char *_base; int _size; } _lb; \
49                          int _blksize; \
50                          fpos_t _offset; \
51                          /* More fields, not relevant here.  */ \
52                        } *) fp)
53   /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>.  */
54 #  define _p pub._p
55 #  define _flags pub._flags
56 #  define _r pub._r
57 #  define _w pub._w
58 # else
59 #  define fp_ fp
60 # endif
61
62 # if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Android */
63   /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
64      and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
65   struct __sfileext
66     {
67       struct  __sbuf _ub; /* ungetc buffer */
68       /* More fields, not relevant here.  */
69     };
70 #  define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
71 # else                                         /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
72 #  define fp_ub fp_->_ub
73 # endif
74
75 # define HASUB(fp) (fp_ub._base != NULL)
76
77 #endif
78
79
80 /* SystemV derived implementations.  */
81
82 #ifdef __TANDEM                     /* NonStop Kernel */
83 # ifndef _IOERR
84 /* These values were determined by the program 'stdioext-flags' at
85    <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>.  */
86 #  define _IOERR   0x40
87 #  define _IOREAD  0x80
88 #  define _IOWRT    0x4
89 #  define _IORW   0x100
90 # endif
91 #endif
92
93 #if defined _IOERR
94
95 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
96 #  define fp_ ((struct { unsigned char *_ptr; \
97                          unsigned char *_base; \
98                          unsigned char *_end; \
99                          long _cnt; \
100                          int _file; \
101                          unsigned int _flag; \
102                        } *) fp)
103 # else
104 #  define fp_ fp
105 # endif
106
107 # if defined _SCO_DS                /* OpenServer */
108 #  define _cnt __cnt
109 #  define _ptr __ptr
110 #  define _base __base
111 #  define _flag __flag
112 # endif
113
114 #endif