:i	static char d_fclose_sccs_id[] = "%W% %G%";
:1#include "V_s_lc.h"
/*
* This is a wrapper for the fclose(p) function.  Note that we no longer  free
* the  space  for  the  name,  so  that  it  can  be used in subsequent debug
* messages.  This means that other routines must  check  to  free  it  before
* re-use,  or we will have memory leaks.  Note also that we return failure if
* Fileno(p) > openfilemax, so we may fail for files that were opened via direct
* calls to the open() or fopen() library functions.  That is, you should only
* call Fclose() for files that were opened via d_open()  or  d_fopen().   See
* d_open() and d_fopen() for further info.
*/
d_fclose(p)
	FILE*p;
{	int  f, v;
	File *fp;
:8	ChkNull(p,"FILE");
	f = Fileno(p);
:3	if (f < 0 || f > openfilemax) {
:8		V3 "Called with Fileno(%08X)=%d.",p,f D;
:3		Fail;
:3	}
	if (!(fp = d_openfile(f))) {
:3		V3 "Can't find file %d descriptor.",f D;
		Fail;
	}
:8	V8s "fclose(%06X->%d=\"%s\")",p,Fileno(p),DspSV(fp->name) D;
	errno = 0;

	v = fclose(p);

:6	V3s "==fclose(%06X->%d=\"%s\")=%d [Err %d=%s=%s]", p,f,DspSV(fp->name),v,Errinfo D;
	fp->flgs = 0;
	fp->addr = 0;
	fp->port = 0;
	return v;
fail:
	errno = EBADF;
	return -1;
}
