os/ossrv/genericopenlibs/cstdlib/LSTDIO/WSETUP.C
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/WSETUP.C	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* WSETUP.C
     1.5 + * 
     1.6 + * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
     1.7 + * All rights reserved.
     1.8 + */
     1.9 +
    1.10 +/* No user fns here. Pesch 15apr92. */
    1.11 +
    1.12 +/*
    1.13 + * Copyright (c) 1990 The Regents of the University of California.
    1.14 + * All rights reserved.
    1.15 + *
    1.16 + * Redistribution and use in source and binary forms are permitted
    1.17 + * provided that the above copyright notice and this paragraph are
    1.18 + * duplicated in all such forms and that any documentation,
    1.19 + * advertising materials, and other materials related to such
    1.20 + * distribution and use acknowledge that the software was developed
    1.21 + * by the University of California, Berkeley.  The name of the
    1.22 + * University may not be used to endorse or promote products derived
    1.23 + * from this software without specific prior written permission.
    1.24 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
    1.25 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
    1.26 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    1.27 + */
    1.28 +
    1.29 +#include <stdio_r.h>
    1.30 +#include <stdlib_r.h>
    1.31 +#include "LOCAL.H"
    1.32 +
    1.33 +/*
    1.34 + * Various output routines call wsetup to be sure it is safe to write,
    1.35 + * because either _flags does not include __SWR, or _buf is NULL.
    1.36 + * _wsetup returns 0 if OK to write, nonzero otherwise.
    1.37 + */
    1.38 +
    1.39 +int
    1.40 +__swsetup (register FILE * fp)
    1.41 +{
    1.42 +  /* Make sure stdio is set up.  */
    1.43 +
    1.44 +  CHECK_INIT (fp);
    1.45 +
    1.46 +  /*
    1.47 +   * If we are not writing, we had better be reading and writing.
    1.48 +   */
    1.49 +
    1.50 +  if ((fp->_flags & __SWR) == 0)
    1.51 +    {
    1.52 +      if ((fp->_flags & __SRW) == 0)
    1.53 +	return EOF;
    1.54 +      if (fp->_flags & __SRD)
    1.55 +	{
    1.56 +	  /* clobber any ungetc data */
    1.57 +	  if (HASUB (fp))
    1.58 +	    FREEUB (fp);
    1.59 +	  fp->_flags &= ~(__SRD | __SEOF);
    1.60 +	  fp->_r = 0;
    1.61 +	  fp->_p = fp->_bf._base;
    1.62 +	}
    1.63 +      fp->_flags |= __SWR;
    1.64 +    }
    1.65 +
    1.66 +  /*
    1.67 +   * Make a buffer if necessary, then set _w.
    1.68 +   */
    1.69 +  /* NOT NEEDED FOR CYGNUS SPRINTF ONLY jpg */
    1.70 +  if (fp->_bf._base == NULL)
    1.71 +    __smakebuf (fp);
    1.72 +
    1.73 +  if (fp->_flags & __SLBF)
    1.74 +    {
    1.75 +      /*
    1.76 +       * It is line buffered, so make _lbfsize be -_bufsize
    1.77 +       * for the putc() macro.  We will change _lbfsize back
    1.78 +       * to 0 whenever we turn off __SWR.
    1.79 +       */
    1.80 +      fp->_w = 0;
    1.81 +      fp->_lbfsize = -fp->_bf._size;
    1.82 +    }
    1.83 +  else
    1.84 +    fp->_w = fp->_flags & __SNBF ? 0 : fp->_bf._size;
    1.85 +
    1.86 +  return 0;
    1.87 +}