Lines Matching refs:f

30 int sfclose(Sfio_t* f)  in sfclose()  argument
32 int sfclose(f) in sfclose()
33 Sfio_t* f; in sfclose()
38 SFMTXDECL(f); /* declare a local stream variable for multithreading */
40 SFMTXENTER(f, -1);
42 GETLOCAL(f,local);
44 if(!(f->mode&SF_INIT) &&
45 SFMODE(f,local) != (f->mode&SF_RDWR) &&
46 SFMODE(f,local) != (f->mode&(SF_READ|SF_SYNCED)) &&
47 _sfmode(f,SF_SYNCED,local) < 0)
48 SFMTXRETURN(f,-1);
51 while(f->push)
54 if(!(pop = (*_Sfstack)(f,NIL(Sfio_t*))) )
55 SFMTXRETURN(f,-1);
58 { (*_Sfstack)(f,pop);
59 SFMTXRETURN(f,-1);
64 if(f->disc == _Sfudisc) /* closing the ungetc stream */
65 f->disc = NIL(Sfdisc_t*);
66 else if(f->file >= 0) /* sync file pointer */
67 { f->bits |= SF_ENDING;
68 rv = sfsync(f);
71 SFLOCK(f,0);
74 if(f->disc && (ex = SFRAISE(f,local ? SF_NEW : SF_CLOSING,NIL(Void_t*))) != 0)
75 SFMTXRETURN(f,ex);
77 if(!local && f->pool)
79 if(f->pool == &_Sfpool)
84 { if(_Sfpool.sf[n] != f)
95 { f->mode &= ~SF_LOCK; /**/ASSERT(_Sfpmove);
96 if((*_Sfpmove)(f,-1) < 0)
97 { SFOPEN(f,0);
98 SFMTXRETURN(f,-1);
100 f->mode |= SF_LOCK;
102 f->pool = NIL(Sfpool_t*);
105 if(f->data && (!local || (f->flags&SF_STRING) || (f->bits&SF_MMAP) ) )
108 if(f->bits&SF_MMAP)
109 SFMUNMAP(f,f->data,f->endb-f->data);
112 if(f->flags&SF_MALLOC)
113 data = (Void_t*)f->data;
115 f->data = NIL(uchar*);
116 f->size = -1;
121 (*_Sfnotify)(f, SF_CLOSING, (void*)((long)f->file));
122 if(f->file >= 0 && !(f->flags&SF_STRING))
123 { while(sysclosef(f->file) < 0 )
132 f->file = -1;
134 SFKILL(f);
135 f->flags &= SF_STATIC;
136 f->here = 0;
137 f->extent = -1;
138 f->endb = f->endr = f->endw = f->next = f->data;
141 if(f->rsrv)
142 { free(f->rsrv);
143 f->rsrv = NIL(Sfrsrv_t*);
147 if(f->proc)
148 rv = _sfpclose(f);
151 if(f->mutex)
152 { (void)vtmtxclrlock(f->mutex);
153 if(f != sfstdin && f != sfstdout && f != sfstderr)
154 { (void)vtmtxclose(f->mutex);
155 f->mutex = NIL(Vtmutex_t*);
160 { if(f->disc && (ex = SFRAISE(f,SF_FINAL,NIL(Void_t*))) != 0 )
165 if(!(f->flags&SF_STATIC) )
166 free(f);
168 { f->disc = NIL(Sfdisc_t*);
169 f->stdio = NIL(Void_t*);
170 f->mode = SF_AVAIL;