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/] [wsetup.c] - Blame information for rev 179

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* No user fns here. Pesch 15apr92. */
2
 
3
/*
4
 * Copyright (c) 1990, 2007 The Regents of the University of California.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms are permitted
8
 * provided that the above copyright notice and this paragraph are
9
 * duplicated in all such forms and that any documentation,
10
 * advertising materials, and other materials related to such
11
 * distribution and use acknowledge that the software was developed
12
 * by the University of California, Berkeley.  The name of the
13
 * University may not be used to endorse or promote products derived
14
 * from this software without specific prior written permission.
15
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18
 */
19
 
20
#include <_ansi.h>
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include "local.h"
24
 
25
/*
26
 * Various output routines call wsetup to be sure it is safe to write,
27
 * because either _flags does not include __SWR, or _buf is NULL.
28
 * _wsetup returns 0 if OK to write, nonzero otherwise.
29
 */
30
 
31
int
32
_DEFUN(__swsetup_r, (ptr, fp),
33
       struct _reent *ptr _AND
34
       register FILE * fp)
35
{
36
  /* Make sure stdio is set up.  */
37
 
38
  CHECK_INIT (_REENT, fp);
39
 
40
  /*
41
   * If we are not writing, we had better be reading and writing.
42
   */
43
 
44
  if ((fp->_flags & __SWR) == 0)
45
    {
46
      if ((fp->_flags & __SRW) == 0)
47
        return EOF;
48
      if (fp->_flags & __SRD)
49
        {
50
          /* clobber any ungetc data */
51
          if (HASUB (fp))
52
            FREEUB (ptr, fp);
53
          fp->_flags &= ~(__SRD | __SEOF);
54
          fp->_r = 0;
55
          fp->_p = fp->_bf._base;
56
        }
57
      fp->_flags |= __SWR;
58
    }
59
 
60
  /*
61
   * Make a buffer if necessary, then set _w.
62
   * A string I/O file should not explicitly allocate a buffer
63
   * unless asprintf is being used.
64
   */
65
  if (fp->_bf._base == NULL
66
        && (!(fp->_flags & __SSTR) || (fp->_flags & __SMBF)))
67
    __smakebuf_r (ptr, fp);
68
 
69
  if (fp->_flags & __SLBF)
70
    {
71
      /*
72
       * It is line buffered, so make _lbfsize be -_bufsize
73
       * for the putc() macro.  We will change _lbfsize back
74
       * to 0 whenever we turn off __SWR.
75
       */
76
      fp->_w = 0;
77
      fp->_lbfsize = -fp->_bf._size;
78
    }
79
  else
80
    fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
81
 
82
  return (!fp->_bf._base && (fp->_flags & __SMBF)) ? EOF : 0;
83
}

powered by: WebSVN 2.1.0

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