/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#include "sfhdr.h"2223/* Function to clear a locked stream.24** This is useful for programs that longjmp from the mid of an sfio function.25** There is no guarantee on data integrity in such a case.26**27** Written by Kiem-Phong Vo28*/29#if __STD_C30int sfclrlock(Sfio_t* f)31#else32int sfclrlock(f)33Sfio_t *f;34#endif35{36int rv;37SFMTXDECL(f); /* declare a local stream variable for multithreading */3839/* already closed */40if(f && (f->mode&SF_AVAIL))41return 0;4243SFMTXENTER(f,0);4445/* clear error bits */46f->flags &= ~(SF_ERROR|SF_EOF);4748/* clear peek locks */49if(f->mode&SF_PKRD)50{ f->here -= f->endb-f->next;51f->endb = f->next;52}5354SFCLRBITS(f);5556/* throw away all lock bits except for stacking state SF_PUSH */57f->mode &= (SF_RDWR|SF_INIT|SF_POOL|SF_PUSH|SF_SYNCED|SF_STDIO);5859rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SF_FLAGS);6061SFMTXRETURN(f, rv);62}636465