开发者

Passing one va_list as a parameter to another

开发者 https://www.devze.com 2022-12-08 09:06 出处:网络
I\'m creating an application using the fastcgi library, and their method of printing is a little verbose. I\'m trying to wrap their fprintf function in my own method:

I'm creating an application using the fastcgi library, and their method of printing is a little verbose. I'm trying to wrap their fprintf function in my own method:

I would like to turn

FCGX_FPrintF(out, char* fmt, ...);

into

write(char* strFormat, ...);

I've found the magic of va_list but can't find an easy way to pass va_list values into their fprintf function. Is there a way to do this? I know vsprintf and vprintf exist so it must be harder than I imagine it is.开发者_高级运维

If all else fails, I'll just overload a write function


You would have to find the analogue of vfprintf() in the Fast CGI library. It is at least moderately plausible that there is one; the easy way to implement FCGX_FPrintF() is:

void FCGX_FPrintF(FILE *out, char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    FCGX_VFPrintF(out, fmt, args);
    va_end(args);
}

So it is highly probable that the function exists; you will need to check whether it is exposed officially or not.


A quick visit to the Fast CGI web site reveals that the FCGX prefix is used by functions declared in the fgciapp.h header, and that in turn contains:

/*
 *----------------------------------------------------------------------
 *
 * FCGX_FPrintF, FCGX_VFPrintF --
 *
 *      Performs printf-style output formatting and writes the results
 *      to the output stream.
 *
 * Results:
 *      number of bytes written for normal return,
 *      EOF (-1) if an error occurred.
 *
 *----------------------------------------------------------------------
 */
DLLAPI int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...);

DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg);

So, there's the function with the interface completed.


I don't believe there is any way to do this in a platform independent way. I would probably format the string myself using vsprintf then just send that to the printing function.

0

精彩评论

暂无评论...
验证码 换一张
取 消