Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

c++ - Passing one va_list as a parameter to another

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...