(gnus-blocked-images): Clarify privacy implications
[emacs.git] / lib / fpending.c
blob7bc235deda2073f77db7f119c4312a299f604f6d
1 /* fpending.c -- return the number of pending output bytes on a stream
2 Copyright (C) 2000, 2004, 2006-2007, 2009-2018 Free Software Foundation,
3 Inc.
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 <https://www.gnu.org/licenses/>. */
18 /* Written by Jim Meyering. */
20 #include <config.h>
22 /* Specification. */
23 #include "fpending.h"
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. */
29 size_t
30 __fpending (FILE *fp)
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
34 fast macros. */
35 #if defined _IO_EOF_SEEN || defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1
36 /* GNU libc, BeOS, Haiku, Linux libc5 */
37 return fp->_IO_write_ptr - fp->_IO_write_base;
38 #elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
39 /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
40 return fp->_p - fp->_bf._base;
41 #elif defined __EMX__ /* emx+gcc */
42 return fp->_ptr - fp->_buffer;
43 #elif defined __minix /* Minix */
44 return fp_->_ptr - fp_->_buf;
45 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel, OpenVMS */
46 return (fp_->_ptr ? fp_->_ptr - fp_->_base : 0);
47 #elif defined __UCLIBC__ /* uClibc */
48 return (fp->__modeflags & __FLAG_WRITING ? fp->__bufpos - fp->__bufstart : 0);
49 #elif defined __QNX__ /* QNX */
50 return (fp->_Mode & 0x2000 /*_MWRITE*/ ? fp->_Next - fp->_Buf : 0);
51 #elif defined __MINT__ /* Atari FreeMiNT */
52 return fp->__bufp - fp->__buffer;
53 #elif defined EPLAN9 /* Plan9 */
54 return fp->wp - fp->buf;
55 #else
56 # error "Please port gnulib fpending.c to your platform!"
57 return 1;
58 #endif