~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to tools/sfio/sfclrlock.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include        "sfhdr.h"
 
2
 
 
3
/*      Function to clear a locked stream.
 
4
**      This is useful for programs that longjmp from the mid of an sfio function.
 
5
**      There is no guarantee on data integrity in such a case.
 
6
**
 
7
**      Written by Kiem-Phong Vo
 
8
*/
 
9
#if __STD_C
 
10
int sfclrlock(reg Sfio_t* f)
 
11
#else
 
12
int sfclrlock(f)
 
13
reg Sfio_t      *f;
 
14
#endif
 
15
{
 
16
        int     rv;
 
17
 
 
18
        /* already closed */
 
19
        if(f && (f->mode&SF_AVAIL))
 
20
                return 0;
 
21
 
 
22
        SFMTXSTART(f,0);
 
23
 
 
24
        /* clear error bits */
 
25
        f->flags &= ~(SF_ERROR|SF_EOF);
 
26
 
 
27
        /* clear peek locks */
 
28
        if(f->mode&SF_PKRD)
 
29
        {       f->here -= f->endb-f->next;
 
30
                f->endb = f->next;
 
31
        }
 
32
 
 
33
        SFCLRBITS(f);
 
34
 
 
35
        /* throw away all lock bits except for stacking state SF_PUSH */
 
36
        f->mode &= (SF_RDWR|SF_INIT|SF_POOL|SF_PUSH|SF_SYNCED|SF_STDIO);
 
37
 
 
38
        rv = (f->mode&SF_PUSH) ? 0 : (f->flags&SF_FLAGS);
 
39
 
 
40
        SFMTXRETURN(f, rv);
 
41
}