8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / lib / libast / common / sfio / sfclrlock.c
blobf6b3a2466784e5ebc99b171394a6a4cd61155654
1 /***********************************************************************
2 * *
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 *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
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"
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.
28 ** Written by Kiem-Phong Vo
30 #if __STD_C
31 int sfclrlock(Sfio_t* f)
32 #else
33 int sfclrlock(f)
34 Sfio_t *f;
35 #endif
37 int rv;
38 SFMTXDECL(f);
40 /* already closed */
41 if(f && (f->mode&SF_AVAIL))
42 return 0;
44 SFMTXENTER(f,0);
46 /* clear error bits */
47 f->flags &= ~(SF_ERROR|SF_EOF);
49 /* clear peek locks */
50 if(f->mode&SF_PKRD)
51 { f->here -= f->endb-f->next;
52 f->endb = f->next;
55 SFCLRBITS(f);
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);
60 rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SF_FLAGS);
62 SFMTXRETURN(f, rv);