sfputr.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* 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"
/* Put out a null-terminated string
**
** Written by Kiem-Phong Vo.
*/
#if __STD_C
#else
char* s; /* string to write */
#endif
{
SFMTXSTART(f,-1);
SFMTXRETURN(f, -1);
SFLOCK(f,0);
for(w = 0; (*s || rc >= 0); )
{ n = strlen(s);
if(p >= (n + (rc < 0 ? 0 : 1)) )
{ /* buffer can hold everything */
if(n > 0)
ps += n;
w += n;
}
if(rc >= 0)
w += 1;
}
}
else
{ /* create a reserve buffer to hold data */
p = n + (rc >= 0 ? 1 : 0);
n = 0;
else
{ if(n > 0)
if(rc >= 0)
n = 0;
}
w += n;
}
break;
}
if(*s == 0)
w += 1;
break;
}
ps -= 1;
#else
for(; p > 0; --p, ++ps, ++s)
if((*ps = *s) == 0)
break;
#endif
}
/* sync unseekable shared streams */
(void)SFFLSBUF(f,-1);
/* check for line buffering */
{ if(n > w)
n = w;
f->next -= n;
}
SFOPEN(f,0);
SFMTXRETURN(f, w);
}