os/ossrv/genericopenlibs/cstdlib/LSTDIO/WSETUP.C
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* WSETUP.C
sl@0
     2
 * 
sl@0
     3
 * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     4
 * All rights reserved.
sl@0
     5
 */
sl@0
     6
sl@0
     7
/* No user fns here. Pesch 15apr92. */
sl@0
     8
sl@0
     9
/*
sl@0
    10
 * Copyright (c) 1990 The Regents of the University of California.
sl@0
    11
 * All rights reserved.
sl@0
    12
 *
sl@0
    13
 * Redistribution and use in source and binary forms are permitted
sl@0
    14
 * provided that the above copyright notice and this paragraph are
sl@0
    15
 * duplicated in all such forms and that any documentation,
sl@0
    16
 * advertising materials, and other materials related to such
sl@0
    17
 * distribution and use acknowledge that the software was developed
sl@0
    18
 * by the University of California, Berkeley.  The name of the
sl@0
    19
 * University may not be used to endorse or promote products derived
sl@0
    20
 * from this software without specific prior written permission.
sl@0
    21
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
sl@0
    22
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
sl@0
    23
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
sl@0
    24
 */
sl@0
    25
sl@0
    26
#include <stdio_r.h>
sl@0
    27
#include <stdlib_r.h>
sl@0
    28
#include "LOCAL.H"
sl@0
    29
sl@0
    30
/*
sl@0
    31
 * Various output routines call wsetup to be sure it is safe to write,
sl@0
    32
 * because either _flags does not include __SWR, or _buf is NULL.
sl@0
    33
 * _wsetup returns 0 if OK to write, nonzero otherwise.
sl@0
    34
 */
sl@0
    35
sl@0
    36
int
sl@0
    37
__swsetup (register FILE * fp)
sl@0
    38
{
sl@0
    39
  /* Make sure stdio is set up.  */
sl@0
    40
sl@0
    41
  CHECK_INIT (fp);
sl@0
    42
sl@0
    43
  /*
sl@0
    44
   * If we are not writing, we had better be reading and writing.
sl@0
    45
   */
sl@0
    46
sl@0
    47
  if ((fp->_flags & __SWR) == 0)
sl@0
    48
    {
sl@0
    49
      if ((fp->_flags & __SRW) == 0)
sl@0
    50
	return EOF;
sl@0
    51
      if (fp->_flags & __SRD)
sl@0
    52
	{
sl@0
    53
	  /* clobber any ungetc data */
sl@0
    54
	  if (HASUB (fp))
sl@0
    55
	    FREEUB (fp);
sl@0
    56
	  fp->_flags &= ~(__SRD | __SEOF);
sl@0
    57
	  fp->_r = 0;
sl@0
    58
	  fp->_p = fp->_bf._base;
sl@0
    59
	}
sl@0
    60
      fp->_flags |= __SWR;
sl@0
    61
    }
sl@0
    62
sl@0
    63
  /*
sl@0
    64
   * Make a buffer if necessary, then set _w.
sl@0
    65
   */
sl@0
    66
  /* NOT NEEDED FOR CYGNUS SPRINTF ONLY jpg */
sl@0
    67
  if (fp->_bf._base == NULL)
sl@0
    68
    __smakebuf (fp);
sl@0
    69
sl@0
    70
  if (fp->_flags & __SLBF)
sl@0
    71
    {
sl@0
    72
      /*
sl@0
    73
       * It is line buffered, so make _lbfsize be -_bufsize
sl@0
    74
       * for the putc() macro.  We will change _lbfsize back
sl@0
    75
       * to 0 whenever we turn off __SWR.
sl@0
    76
       */
sl@0
    77
      fp->_w = 0;
sl@0
    78
      fp->_lbfsize = -fp->_bf._size;
sl@0
    79
    }
sl@0
    80
  else
sl@0
    81
    fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
sl@0
    82
sl@0
    83
  return 0;
sl@0
    84
}