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 ***********************************************************************/
27 _stdgets(Sfio_t
* f
, char* us
, int n
, int isgets
)
33 if(n
<= 0 || !us
|| (f
->mode
!= SF_READ
&& _sfmode(f
,SF_READ
,0) < 0))
42 { /* peek the read buffer for data */
43 if((p
= f
->endb
- (ps
= f
->next
)) <= 0 )
46 if(SFRPEEK(f
,ps
,p
) <= 0)
54 if((ps
= (uchar
*)memccpy((char*)is
,(char*)ps
,'\n',p
)) != NIL(uchar
*))
59 if(!(f
->flags
&(SF_BOTH
|SF_MALLOC
)))
60 { while(p
-- && (*is
++ = *ps
++) != '\n')
65 { reg
int c
= ps
[p
-1];
68 while((*is
++ = *ps
++) != '\n')
78 /* gobble up read data and continue */
86 if((_Sfi
= is
- ((uchar
*)us
)) <= 0)
88 else if(isgets
&& is
[-1] == '\n')
99 fgets(char* s
, int n
, Sfio_t
* f
)
101 STDIO_PTR(f
, "fgets", char*, (char*, int, Sfio_t
*), (s
, n
, f
))
103 return _stdgets(f
, s
, n
, 0);
109 return _stdgets(sfstdin
, s
, BUFSIZ
, 1);