1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 /* Put out a null-terminated string
26 ** Written by Kiem-Phong Vo.
29 ssize_t
sfputr(Sfio_t
* f
, const char* s
, int rc
)
31 ssize_t
sfputr(f
,s
,rc
)
32 Sfio_t
* f
; /* write to this stream */
33 char* s
; /* string to write */
34 int rc
; /* record separator. */
43 if(f
->mode
!= SF_WRITE
&& _sfmode(f
,SF_WRITE
,0) < 0)
48 for(w
= 0; (*s
|| rc
>= 0); )
49 { if(SFWPEEK(f
,ps
,p
) < 0)
52 if(p
== 0 || (f
->flags
&SF_WHOLE
) )
54 if(p
>= (n
+ (rc
< 0 ? 0 : 1)) )
55 { /* buffer can hold everything */
68 { /* create a reserve buffer to hold data */
71 p
= n
+ (rc
>= 0 ? 1 : 0);
72 if(!(rsrv
= _sfrsrv(f
, p
)) )
76 memcpy(rsrv
->data
, s
, n
);
79 if((n
= SFWRITE(f
,rsrv
->data
,p
)) < 0 )
95 #if _lib_memccpy && !__ia64 /* these guys may never get it right */
96 if((ps
= (uchar
*)memccpy(ps
,s
,'\0',p
)) != NIL(uchar
*))
101 for(; p
> 0; --p
, ++ps
, ++s
)
109 /* sync unseekable shared streams */
110 if(f
->extent
< 0 && (f
->flags
&SF_SHARE
) )
111 (void)SFFLSBUF(f
,-1);
113 /* check for line buffering */
114 else if((f
->flags
&SF_LINE
) && !(f
->flags
&SF_STRING
) && (n
= f
->next
-f
->data
) > 0)
118 (void)SFWRITE(f
,(Void_t
*)f
->next
,n
);