H
hg
I have a function called logprintf that take a printf-like syntax.
On top of that I want to implement a debug-printf function which calls
logprintf but prefix the information using a string:
void _dbglogprintf(const char *szFormat, ...)
{
char szOutput[4096];
va_list arglist;
sprintf(szOutput, "DEBUG: ");
va_start(arglist, szFormat);
vsprintf(szOutput + strlen(szOutput), szFormat, arglist);
va_end(arglist);
logprintf(szOutput);
}
The following works but will obviously cause a buffer overflow when
the string becomes too long.
I want to avoid such problems.
However the obstacle is that logprintf must be called only once since
it prints out information such as time-stamps. If it would be called
twice it would duplicate this information without any good reason.
However I couldn't see if there is a function which allows me to take
the existing arglist and combine it with my own strings.
Thanks.
-- Henrik
On top of that I want to implement a debug-printf function which calls
logprintf but prefix the information using a string:
void _dbglogprintf(const char *szFormat, ...)
{
char szOutput[4096];
va_list arglist;
sprintf(szOutput, "DEBUG: ");
va_start(arglist, szFormat);
vsprintf(szOutput + strlen(szOutput), szFormat, arglist);
va_end(arglist);
logprintf(szOutput);
}
The following works but will obviously cause a buffer overflow when
the string becomes too long.
I want to avoid such problems.
However the obstacle is that logprintf must be called only once since
it prints out information such as time-stamps. If it would be called
twice it would duplicate this information without any good reason.
However I couldn't see if there is a function which allows me to take
the existing arglist and combine it with my own strings.
Thanks.
-- Henrik