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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdio/] [wsetup.c] - Blame information for rev 1773

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

Line No. Rev Author Line
1 1010 ivang
/* No user fns here. Pesch 15apr92. */
2
 
3
/*
4
 * Copyright (c) 1990 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 <stdio.h>
21
#include <stdlib.h>
22
#include "local.h"
23
 
24
/*
25
 * Various output routines call wsetup to be sure it is safe to write,
26
 * because either _flags does not include __SWR, or _buf is NULL.
27
 * _wsetup returns 0 if OK to write, nonzero otherwise.
28
 */
29
 
30
int
31
_DEFUN (__swsetup, (fp),
32
        register FILE * fp)
33
{
34
  /* Make sure stdio is set up.  */
35
 
36
  CHECK_INIT (fp);
37
 
38
  /*
39
   * If we are not writing, we had better be reading and writing.
40
   */
41
 
42
  if ((fp->_flags & __SWR) == 0)
43
    {
44
      if ((fp->_flags & __SRW) == 0)
45
        return EOF;
46
      if (fp->_flags & __SRD)
47
        {
48
          /* clobber any ungetc data */
49
          if (HASUB (fp))
50
            FREEUB (fp);
51
          fp->_flags &= ~(__SRD | __SEOF);
52
          fp->_r = 0;
53
          fp->_p = fp->_bf._base;
54
        }
55
      fp->_flags |= __SWR;
56
    }
57
 
58
  /*
59
   * Make a buffer if necessary, then set _w.
60
   */
61
  /* NOT NEEDED FOR CYGNUS SPRINTF ONLY jpg */
62
  if (fp->_bf._base == NULL)
63
    __smakebuf (fp);
64
 
65
  if (fp->_flags & __SLBF)
66
    {
67
      /*
68
       * It is line buffered, so make _lbfsize be -_bufsize
69
       * for the putc() macro.  We will change _lbfsize back
70
       * to 0 whenever we turn off __SWR.
71
       */
72
      fp->_w = 0;
73
      fp->_lbfsize = -fp->_bf._size;
74
    }
75
  else
76
    fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
77
 
78
  return 0;
79
}

powered by: WebSVN 2.1.0

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