	static char D_write_sccs_id[] = "%W% %G%";
#include "V_s.h"
/*
* The debug wrapper for write() has a special trickiness:  There is a  serious
* risk of infinite recursion in the debug output code itself.  So we decrement
* the debug level on entry, and jack it back up just before we return. Thus if
* we  call  ourself,  we  will  only do so a few times before Vlvl will fall
* below our threshold. This means that the "effective" debug levels of all the
* messages here are one lower than they appear to be.
*/
extern Flag Vchknull;		/* If true, check for nulls */
extern int  Vmaxnull;		/* If true, max length string of nulls */
extern int  Vlennull;		/* Longest string of nulls so far */

D_write(f,b,n)
	int   f;
	char* b;
	Sizt  n;
{	int   v;
	int   e, i;
	File *fp;
	--Vlvl;	/* Avoid debug loop */
	if (fp = D_openfile(f))
		fp->writes++;
	if (Vchknull)
		if (i = Vcntnulls(b,n))
			V3 "### String of %d nulls written to file %d offset %lu write %d."
				,i,f,(fp?fp->addr:0),(fp?fp->writes:0) D;
#if defined(USE_syscall) && defined(SYS_write)
	V8s "syscall(SYS_write,%d,%07lX,%u)",f,b,n D;
	v = syscall(SYS_write,f,b,n);
	e = errno;
	V7s "syscall(SYS_write,%d,%08lX,%d)=%d [Err %d=%s=%s]",f,b,n,v,Errinfo D;
#else
	V8s "write(%d,%07lX,%u)",f,b,n D;
	v = write(f,b,n);
	e = errno;
	V7s "write(%d,%08lX,%d)=%d [Err %d=%s=%s]",f,b,n,v,Errinfo D;
#endif
	++dbn_write;
	if (v > 0) {
		H7s(b,v,"write");
		if (fp) fp->addr += v;	/* Keep track of the offset */
	}
	++Vlvl;
	errno = e;
	return v;
}
/*
* Intercepting write() itself is even riskier ...
*/
#if defined(USE_syscall) && defined(SYS_write)
write(f,b,n)
	char *b;
{	int   v;
	--Vlvl;	/* Avoid debug loop */







	v = D_write(f,b,n);


	++Vlvl;
	return v;
}
#endif
