1 /* fpending.c -- return the number of pending output bytes on a stream
2 Copyright (C) 2000, 2004, 2006-2007, 2009-2017 Free Software Foundation,
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* Written by Jim Meyering. */
25 #include "stdio-impl.h"
27 /* Return the number of pending (aka buffered, unflushed)
28 bytes on the stream, FP, that is open for writing. */
32 /* Most systems provide FILE as a struct and the necessary bitmask in
33 <stdio.h>, because they need it for implementing getc() and putc() as
35 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
36 return fp
->_IO_write_ptr
- fp
->_IO_write_base
;
37 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
38 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
39 return fp
->_p
- fp
->_bf
._base
;
40 #elif defined __EMX__ /* emx+gcc */
41 return fp
->_ptr
- fp
->_buffer
;
42 #elif defined __minix /* Minix */
43 return fp_
->_ptr
- fp_
->_buf
;
44 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel */
45 return (fp_
->_ptr
? fp_
->_ptr
- fp_
->_base
: 0);
46 #elif defined __UCLIBC__ /* uClibc */
47 return (fp
->__modeflags
& __FLAG_WRITING
? fp
->__bufpos
- fp
->__bufstart
: 0);
48 #elif defined __QNX__ /* QNX */
49 return (fp
->_Mode
& 0x2000 /*_MWRITE*/ ? fp
->_Next
- fp
->_Buf
: 0);
50 #elif defined __MINT__ /* Atari FreeMiNT */
51 return fp
->__bufp
- fp
->__buffer
;
52 #elif defined EPLAN9 /* Plan9 */
53 return fp
->wp
- fp
->buf
;
54 #elif defined __VMS /* VMS */
55 return (*fp
)->_ptr
- (*fp
)->_base
;
57 # error "Please port gnulib fpending.c to your platform!"