/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#include "sfhdr.h"
/* Close a stream. A file stream is synced before closing.
**
** Written by Kiem-Phong Vo
*/
#if __STD_C
#else
int sfclose(f)
Sfio_t* f;
#endif
{
SFMTXDECL(f); /* declare a local stream variable for multithreading */
SFMTXENTER(f, -1);
SFMTXRETURN(f,-1);
/* closing a stack of streams */
while(f->push)
SFMTXRETURN(f,-1);
SFMTXRETURN(f,-1);
}
}
rv = 0;
else if(f->file >= 0) /* sync file pointer */
}
SFLOCK(f,0);
/* raise discipline exceptions */
SFMTXRETURN(f,ex);
{ /* remove from pool */
{ reg int n;
continue;
/* found it */
break;
}
}
else
if((*_Sfpmove)(f,-1) < 0)
{ SFOPEN(f,0);
SFMTXRETURN(f,-1);
}
}
}
{ /* free buffer */
#ifdef MAP_TYPE
else
#endif
f->size = -1;
}
/* zap the file descriptor */
if(_Sfnotify)
errno = 0;
else
{ rv = -1;
break;
}
}
}
f->file = -1;
SFKILL(f);
f->here = 0;
f->extent = -1;
/* zap any associated auxiliary buffer */
if(f->rsrv)
}
/* delete any associated sfpopen-data */
if(f->proc)
/* destroy the mutex */
if(f->mutex)
{ (void)vtmtxclrlock(f->mutex);
{ (void)vtmtxclose(f->mutex);
}
}
if(!local)
goto done;
}
free(f);
else
}
}
done:
if(data)
return rv;
}