1 /*********************************************************************** 2 * * 3 * This software is part of the ast package * 4 * Copyright (c) 1985-2011 AT&T Intellectual Property * 5 * and is licensed under the * 6 * Eclipse Public License, Version 1.0 * 7 * by AT&T Intellectual Property * 8 * * 9 * A copy of the License is available at * 10 * http://www.eclipse.org/org/documents/epl-v10.html * 11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12 * * 13 * Information and Software Systems Research * 14 * AT&T Research * 15 * Florham Park NJ * 16 * * 17 * Glenn Fowler <gsf@research.att.com> * 18 * David Korn <dgk@research.att.com> * 19 * Phong Vo <kpv@research.att.com> * 20 * * 21 ***********************************************************************/ 22 #include "sfhdr.h" 23 24 /* Function to clear a locked stream. 25 ** This is useful for programs that longjmp from the mid of an sfio function. 26 ** There is no guarantee on data integrity in such a case. 27 ** 28 ** Written by Kiem-Phong Vo 29 */ 30 #if __STD_C sfclrlock(Sfio_t * f)31int sfclrlock(Sfio_t* f) 32 #else 33 int sfclrlock(f) 34 Sfio_t *f; 35 #endif 36 { 37 int rv; 38 SFMTXDECL(f); /* declare a local stream variable for multithreading */ 39 40 /* already closed */ 41 if(f && (f->mode&SF_AVAIL)) 42 return 0; 43 44 SFMTXENTER(f,0); 45 46 /* clear error bits */ 47 f->flags &= ~(SF_ERROR|SF_EOF); 48 49 /* clear peek locks */ 50 if(f->mode&SF_PKRD) 51 { f->here -= f->endb-f->next; 52 f->endb = f->next; 53 } 54 55 SFCLRBITS(f); 56 57 /* throw away all lock bits except for stacking state SF_PUSH */ 58 f->mode &= (SF_RDWR|SF_INIT|SF_POOL|SF_PUSH|SF_SYNCED|SF_STDIO); 59 60 rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SF_FLAGS); 61 62 SFMTXRETURN(f, rv); 63 } 64