; Change instrumentation code in tramp-tests.el
[emacs.git] / lib / stdio-impl.h
blobd5b5943fd7c5584637c6100d275ab4df87b61da7
1 /* Implementation details of FILE streams.
2 Copyright (C) 2007-2008, 2010-2017 Free Software Foundation, Inc.
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.
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.
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/>. */
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. */
22 /* BSD stdio derived implementations. */
24 #if defined __NetBSD__ /* NetBSD */
25 /* Get __NetBSD_Version__. */
26 # include <sys/param.h>
27 #endif
29 #include <errno.h> /* For detecting Plan9. */
31 #if defined __sferror || defined __DragonFly__ || defined __ANDROID__
32 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
34 # if defined __DragonFly__ /* DragonFly */
35 /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
36 # define fp_ ((struct { struct __FILE_public pub; \
37 struct { unsigned char *_base; int _size; } _bf; \
38 void *cookie; \
39 void *_close; \
40 void *_read; \
41 void *_seek; \
42 void *_write; \
43 struct { unsigned char *_base; int _size; } _ub; \
44 int _ur; \
45 unsigned char _ubuf[3]; \
46 unsigned char _nbuf[1]; \
47 struct { unsigned char *_base; int _size; } _lb; \
48 int _blksize; \
49 fpos_t _offset; \
50 /* More fields, not relevant here. */ \
51 } *) fp)
52 /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
53 # define _p pub._p
54 # define _flags pub._flags
55 # define _r pub._r
56 # define _w pub._w
57 # else
58 # define fp_ fp
59 # endif
61 # if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Minix 3, Android */
62 /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
63 and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
64 struct __sfileext
66 struct __sbuf _ub; /* ungetc buffer */
67 /* More fields, not relevant here. */
69 # define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
70 # else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin, Android */
71 # define fp_ub fp_->_ub
72 # endif
74 # define HASUB(fp) (fp_ub._base != NULL)
76 #endif
79 /* SystemV derived implementations. */
81 #ifdef __TANDEM /* NonStop Kernel */
82 # ifndef _IOERR
83 /* These values were determined by the program 'stdioext-flags' at
84 <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
85 # define _IOERR 0x40
86 # define _IOREAD 0x80
87 # define _IOWRT 0x4
88 # define _IORW 0x100
89 # endif
90 #endif
92 #if defined _IOERR
94 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
95 # define fp_ ((struct { unsigned char *_ptr; \
96 unsigned char *_base; \
97 unsigned char *_end; \
98 long _cnt; \
99 int _file; \
100 unsigned int _flag; \
101 } *) fp)
102 # elif defined __VMS /* OpenVMS */
103 # define fp_ ((struct _iobuf *) fp)
104 # else
105 # define fp_ fp
106 # endif
108 # if defined _SCO_DS /* OpenServer */
109 # define _cnt __cnt
110 # define _ptr __ptr
111 # define _base __base
112 # define _flag __flag
113 # endif
115 #elif (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ /* newer Windows with MSVC */
117 /* <stdio.h> does not define the innards of FILE any more. */
118 # define WINDOWS_OPAQUE_FILE
120 struct _gl_real_FILE
122 /* Note: Compared to older Windows and to mingw, it has the fields
123 _base and _cnt swapped. */
124 unsigned char *_ptr;
125 unsigned char *_base;
126 int _cnt;
127 int _flag;
128 int _file;
129 int _charbuf;
130 int _bufsiz;
132 # define fp_ ((struct _gl_real_FILE *) fp)
134 /* These values were determined by a program similar to the one at
135 <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
136 # define _IOREAD 0x1
137 # define _IOWRT 0x2
138 # define _IORW 0x4
139 # define _IOEOF 0x8
140 # define _IOERR 0x10
142 #endif