signed-unsigned comparison fixes and removed unused parameter.
[gnutls.git] / gl / stdio-impl.h
blob920b4d47daad0fc7e1c44fcfcf2130a95522f572
1 /* Implementation details of FILE streams.
2 Copyright (C) 2007-2008, 2010-2012 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__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
33 # if defined __DragonFly__ /* DragonFly */
34 /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
35 # define fp_ ((struct { struct __FILE_public pub; \
36 struct { unsigned char *_base; int _size; } _bf; \
37 void *cookie; \
38 void *_close; \
39 void *_read; \
40 void *_seek; \
41 void *_write; \
42 struct { unsigned char *_base; int _size; } _ub; \
43 int _ur; \
44 unsigned char _ubuf[3]; \
45 unsigned char _nbuf[1]; \
46 struct { unsigned char *_base; int _size; } _lb; \
47 int _blksize; \
48 fpos_t _offset; \
49 /* More fields, not relevant here. */ \
50 } *) fp)
51 /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
52 # define _p pub._p
53 # define _flags pub._flags
54 # define _r pub._r
55 # define _w pub._w
56 # else
57 # define fp_ fp
58 # endif
60 # if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ /* NetBSD >= 1.5ZA, OpenBSD */
61 /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
62 and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
63 struct __sfileext
65 struct __sbuf _ub; /* ungetc buffer */
66 /* More fields, not relevant here. */
68 # define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
69 # else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
70 # define fp_ub fp_->_ub
71 # endif
73 # define HASUB(fp) (fp_ub._base != NULL)
75 #endif
78 /* SystemV derived implementations. */
80 #ifdef __TANDEM /* NonStop Kernel */
81 # ifndef _IOERR
82 /* These values were determined by the program 'stdioext-flags' at
83 <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
84 # define _IOERR 0x40
85 # define _IOREAD 0x80
86 # define _IOWRT 0x4
87 # define _IORW 0x100
88 # endif
89 #endif
91 #if defined _IOERR
93 # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
94 # define fp_ ((struct { unsigned char *_ptr; \
95 unsigned char *_base; \
96 unsigned char *_end; \
97 long _cnt; \
98 int _file; \
99 unsigned int _flag; \
100 } *) fp)
101 # else
102 # define fp_ fp
103 # endif
105 # if defined _SCO_DS /* OpenServer */
106 # define _cnt __cnt
107 # define _ptr __ptr
108 # define _base __base
109 # define _flag __flag
110 # endif
112 #endif