/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Write data out to the file system
**
** Written by Kiem-Phong Vo.
*/
#if __STD_C
#else
Sfio_t* f; /* write to this stream. */
size_t n; /* number of bytes. */
#endif
{
SFMTXDECL(f);
if(!buf)
/* release peek lock */
{ /* read past peeked data */
for(w = n; w > 0; )
{ if((r = w) > sizeof(buf))
r = sizeof(buf);
{ n -= w;
break;
}
else w -= r;
}
f->here += n;
}
f->next += n;
}
{ /* check stream mode */
SFMTXRETURN(f,w);
}
{ if(w > (ssize_t)n)
w = (ssize_t)n;
f->next = (s += w);
n -= w;
break;
}
/* attempt to create space in buffer */
goto fls_buf;
}
else if(w == 0)
break;
}
}
{ fls_buf:
(void)SFFLSBUF(f, -1);
break;
}
}
{ /* bypass buffering */
break;
}
else
{ if(w > (ssize_t)n)
w = (ssize_t)n;
if(w <= 0) /* no forward progress possible */
break;
f->next += w;
}
s += w;
if((n -= w) <= 0)
break;
}
/* always flush buffer for share streams */
(void)SFFLSBUF(f,-1);
/* check to see if buffer should be flushed */
n = w;
if(n > 0 && n < HIFORLINE)
{ if(*next == '\n')
{ n = HIFORLINE;
break;
}
}
}
if(n >= HIFORLINE)
(void)SFFLSBUF(f,-1);
}
w = s-begs;
SFMTXRETURN(f,w);
}