xref: /onnv-gate/usr/src/lib/libast/common/sfio/sfclrlock.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #include	"sfhdr.h"
234887Schin 
244887Schin /*	Function to clear a locked stream.
254887Schin **	This is useful for programs that longjmp from the mid of an sfio function.
264887Schin **	There is no guarantee on data integrity in such a case.
274887Schin **
284887Schin **	Written by Kiem-Phong Vo
294887Schin */
304887Schin #if __STD_C
sfclrlock(Sfio_t * f)318462SApril.Chin@Sun.COM int sfclrlock(Sfio_t* f)
324887Schin #else
334887Schin int sfclrlock(f)
348462SApril.Chin@Sun.COM Sfio_t	*f;
354887Schin #endif
364887Schin {
374887Schin 	int	rv;
388462SApril.Chin@Sun.COM 	SFMTXDECL(f);
394887Schin 
404887Schin 	/* already closed */
414887Schin 	if(f && (f->mode&SF_AVAIL))
424887Schin 		return 0;
434887Schin 
448462SApril.Chin@Sun.COM 	SFMTXENTER(f,0);
454887Schin 
464887Schin 	/* clear error bits */
474887Schin 	f->flags &= ~(SF_ERROR|SF_EOF);
484887Schin 
494887Schin 	/* clear peek locks */
504887Schin 	if(f->mode&SF_PKRD)
514887Schin 	{	f->here -= f->endb-f->next;
524887Schin 		f->endb = f->next;
534887Schin 	}
544887Schin 
554887Schin 	SFCLRBITS(f);
564887Schin 
574887Schin 	/* throw away all lock bits except for stacking state SF_PUSH */
584887Schin 	f->mode &= (SF_RDWR|SF_INIT|SF_POOL|SF_PUSH|SF_SYNCED|SF_STDIO);
594887Schin 
604887Schin 	rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SF_FLAGS);
614887Schin 
624887Schin 	SFMTXRETURN(f, rv);
634887Schin }
64