Does anybody have a version of SPRINTF with bounds checking and flame

Chris Torek chris at umcp-cs.UUCP
Mon Aug 20 23:09:05 AEST 1984


I've already complained about that one here.  Here's an ``sprintfl''
that does a counted sprintf and works on BSD Vaxen:

#include <stdio.h>

char *sprintfl (buf, len, fmt, arg)
register char *buf;
register int len;
char *fmt;
{
    struct _iobuf s;

    if (len <= 0)
	return;
    if (--len <= 0) {	/* use sobgtr */
	*buf = 0;
	return;
    }
    s._ptr = buf;
    s._cnt = len;
    s._flag = _IOSTRG;	/* leave out _IOWRT! */
    _doprnt (fmt, &arg, &s);
    buf[len] = 0;
    return buf;
}
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci (301) 454-7690
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.unix.wizards mailing list