Blame lib/fpending.c

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