OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdio/] [wbuf.c] - Diff between revs 148 and 158

Only display areas with differences | Details | Blame | View Log

Rev 148 Rev 158
/*
/*
 * Copyright (c) 1990 The Regents of the University of California.
 * Copyright (c) 1990 The Regents of the University of California.
 * All rights reserved.
 * All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms are permitted
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * distribution and use acknowledge that the software was developed
 * by the University of California, Berkeley.  The name of the
 * by the University of California, Berkeley.  The name of the
 * University may not be used to endorse or promote products derived
 * University may not be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * from this software without specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
 */
/* No user fns here.  Pesch 15apr92. */
/* No user fns here.  Pesch 15apr92. */
 
 
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "%W% (Berkeley) %G%";
static char sccsid[] = "%W% (Berkeley) %G%";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <errno.h>
#include "local.h"
#include "local.h"
#include "fvwrite.h"
#include "fvwrite.h"
 
 
/*
/*
 * Write the given character into the (probably full) buffer for
 * Write the given character into the (probably full) buffer for
 * the given file.  Flush the buffer out if it is or becomes full,
 * the given file.  Flush the buffer out if it is or becomes full,
 * or if c=='\n' and the file is line buffered.
 * or if c=='\n' and the file is line buffered.
 */
 */
 
 
int
int
_DEFUN(__swbuf_r, (ptr, c, fp),
_DEFUN(__swbuf_r, (ptr, c, fp),
       struct _reent *ptr _AND
       struct _reent *ptr _AND
       register int c _AND
       register int c _AND
       register FILE *fp)
       register FILE *fp)
{
{
  register int n;
  register int n;
 
 
  /* Ensure stdio has been initialized.  */
  /* Ensure stdio has been initialized.  */
 
 
  CHECK_INIT (ptr, fp);
  CHECK_INIT (ptr, fp);
 
 
  /*
  /*
   * In case we cannot write, or longjmp takes us out early,
   * In case we cannot write, or longjmp takes us out early,
   * make sure _w is 0 (if fully- or un-buffered) or -_bf._size
   * make sure _w is 0 (if fully- or un-buffered) or -_bf._size
   * (if line buffered) so that we will get called again.
   * (if line buffered) so that we will get called again.
   * If we did not do this, a sufficient number of putc()
   * If we did not do this, a sufficient number of putc()
   * calls might wrap _w from negative to positive.
   * calls might wrap _w from negative to positive.
   */
   */
 
 
  fp->_w = fp->_lbfsize;
  fp->_w = fp->_lbfsize;
  if (cantwrite (ptr, fp))
  if (cantwrite (ptr, fp))
    {
    {
      fp->_flags |= __SERR;
      fp->_flags |= __SERR;
      ptr->_errno = EBADF;
      ptr->_errno = EBADF;
      return EOF;
      return EOF;
    }
    }
  c = (unsigned char) c;
  c = (unsigned char) c;
 
 
  ORIENT (fp, -1);
  ORIENT (fp, -1);
 
 
  /*
  /*
   * If it is completely full, flush it out.  Then, in any case,
   * If it is completely full, flush it out.  Then, in any case,
   * stuff c into the buffer.  If this causes the buffer to fill
   * stuff c into the buffer.  If this causes the buffer to fill
   * completely, or if c is '\n' and the file is line buffered,
   * completely, or if c is '\n' and the file is line buffered,
   * flush it (perhaps a second time).  The second flush will always
   * flush it (perhaps a second time).  The second flush will always
   * happen on unbuffered streams, where _bf._size==1; fflush()
   * happen on unbuffered streams, where _bf._size==1; fflush()
   * guarantees that putc() will always call wbuf() by setting _w
   * guarantees that putc() will always call wbuf() by setting _w
   * to 0, so we need not do anything else.
   * to 0, so we need not do anything else.
   */
   */
 
 
  n = fp->_p - fp->_bf._base;
  n = fp->_p - fp->_bf._base;
  if (n >= fp->_bf._size)
  if (n >= fp->_bf._size)
    {
    {
      if (_fflush_r (ptr, fp))
      if (_fflush_r (ptr, fp))
        return EOF;
        return EOF;
      n = 0;
      n = 0;
    }
    }
  fp->_w--;
  fp->_w--;
  *fp->_p++ = c;
  *fp->_p++ = c;
  if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
  if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n'))
    if (_fflush_r (ptr, fp))
    if (_fflush_r (ptr, fp))
      return EOF;
      return EOF;
  return c;
  return c;
}
}
 
 
/* This function isn't any longer declared in stdio.h, but it's
/* This function isn't any longer declared in stdio.h, but it's
   required for backward compatibility with applications built against
   required for backward compatibility with applications built against
   earlier dynamically built newlib libraries. */
   earlier dynamically built newlib libraries. */
int
int
_DEFUN(__swbuf, (c, fp),
_DEFUN(__swbuf, (c, fp),
       register int c _AND
       register int c _AND
       register FILE *fp)
       register FILE *fp)
{
{
  return __swbuf_r (_REENT, c, fp);
  return __swbuf_r (_REENT, c, fp);
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.