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 /* Safe access to the internal stream buffer.
25 ** This function is obsolete. sfreserve() should be used.
27 ** Written by Kiem-Phong Vo (06/27/90).
30 #if _BLD_sfio && defined(__EXPORT__)
31 #define extern __EXPORT__
35 extern ssize_t
sfpeek(reg Sfio_t
* f
, Void_t
** bp
, reg
size_t size
)
37 extern ssize_t
sfpeek(f
,bp
,size
)
38 reg Sfio_t
* f
; /* file to peek */
39 Void_t
** bp
; /* start of data area */
40 reg
size_t size
; /* size of peek */
45 /* query for the extent of the remainder of the buffer */
46 if((sz
= size
) == 0 || !bp
)
50 if((f
->flags
&SF_RDWRSTR
) == SF_RDWRSTR
)
52 n
= (f
->data
+f
->here
) - f
->next
;
54 else n
= f
->endb
- f
->next
;
58 else if(n
> 0) /* size == 0 */
59 { *bp
= (Void_t
*)f
->next
;
62 /* else fall down and fill buffer */
65 if(!(mode
= f
->flags
&SF_READ
) )
67 if((int)f
->mode
!= mode
&& _sfmode(f
,mode
,0) < 0)
70 *bp
= sfreserve(f
, sz
<= 0 ? 0 : sz
> f
->size
? f
->size
: sz
, 0);
75 if((n
= sfvalue(f
)) > 0)
76 { *bp
= (Void_t
*)f
->next
;
79 f
->endr
= f
->endw
= f
->data
;
88 return (sz
>= 0 && n
>= sz
) ? sz
: n
;