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 /* Delete all pending data in the buffer
26 ** Written by Kiem-Phong Vo.
30 int sfpurge(Sfio_t
* f
)
41 if((mode
= f
->mode
&SF_RDWR
) != (int)f
->mode
&& _sfmode(f
,mode
|SF_SYNCED
,0) < 0)
44 if((f
->flags
&SF_IOCHECK
) && f
->disc
&& f
->disc
->exceptf
)
45 (void)(*f
->disc
->exceptf
)(f
,SF_PURGE
,(Void_t
*)((int)1),f
->disc
);
47 if(f
->disc
== _Sfudisc
)
48 (void)sfclose((*_Sfstack
)(f
,NIL(Sfio_t
*)));
50 /* cannot purge read string streams */
51 if((f
->flags
&SF_STRING
) && (f
->mode
&SF_READ
) )
56 /* if memory map must be a read stream, pretend data is gone */
59 { f
->here
-= f
->endb
- f
->next
;
61 { SFMUNMAP(f
,f
->data
,f
->endb
-f
->data
);
62 (void)SFSK(f
,f
->here
,SEEK_SET
,f
->disc
);
69 switch(f
->mode
&~SF_LOCK
)
76 if(!f
->proc
|| !(f
->flags
&SF_READ
) || !(f
->mode
&SF_WRITE
) )
79 /* 2-way pipe, must clear read buffer */
80 (void)_sfmode(f
,SF_READ
,1);
83 if(f
->extent
>= 0 && f
->endb
> f
->next
)
84 { f
->here
-= f
->endb
-f
->next
;
85 (void)SFSK(f
,f
->here
,SEEK_SET
,f
->disc
);
87 f
->endb
= f
->next
= f
->data
;
94 if((f
->flags
&SF_IOCHECK
) && f
->disc
&& f
->disc
->exceptf
)
95 (void)(*f
->disc
->exceptf
)(f
,SF_PURGE
,(Void_t
*)((int)0),f
->disc
);