I'm writing for the MCF5407 on CW6.2.
I need to write a wrapper around sprintf that has the same syntax as sprintf but with an additional parameter. My funtcion will strip out the new parameter for processing, but needs to pass the remaining params to sprintf. My new function needs to have the same syntax as sprintf with the addition of the new param.
My problem has been with handling the value list which follows the format string. Does anyone have any tricks to pass along for doing this?
Here is a skeleton of what I am trying to do:
int dprintf(int flag, char* fmt, ... )
{
extern char global_string[];
// process flag
return sprintf(global_string, fmt, ... );
}
I tried doing some pointer math against fmt, giving me a pointer to the next argument in the dprintf list:
asm int
dprintf(int flag, const char *fmt, ... )
{
char * ap;
if((flag & 0x01) == 0)
{
return 0;
}
ap = (char*) ((char *)&fmt + sizeof(fmt));
return sprintf(OUTSTR, fmt, ap);
}
However, sprintf simply processed the pointer as the first value for the fmt string.
Thanks,
Joe