You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Randy Terbush <ra...@zyzzyva.com> on 1996/05/17 18:36:03 UTC

rprintf()

If someone else has grabbed the horns on getting this working in
an acceptable way, please stop me.  I'm getting tired of doing
type conversions and will probably tackle this in the next few
hours.






Re: rprintf()

Posted by ra...@madhaus.utcs.utoronto.ca.
> If someone else has grabbed the horns on getting this working in
> an acceptable way, please stop me.  I'm getting tired of doing
> type conversions and will probably tackle this in the next few
> hours.

Without vsnprintf() it is extremely tricky to build a safe varargs
printf function.  If you look in the PHP/FI distribution in the echo.c
file you will find a function called FormatCheck():

/*
 * FormatCheck - Scan through format string until first formatter is
 * found and return the type, or -1 on an error.  If no type-checking
 * needs to be done it returns 1, or if no formatting sequences were found,
 * it returns 0.
 * It also advances the format pointer to one past the found formatting
 * sequence and returns the skipped characters along with the formatting
 * sequence itself in *beg and *fmt respectively.
 */
int FormatCheck(char **format, char **beg, char **fmt) {

If you loops through your varargs and call this function for each one,
thereby advancing your way through the format string, you can send each
individual component.  There is still the issue of overflowing buffers
to worry about though.  ie.  "%1000s"

-Rasmus