[英]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.我正在使用 fastcgi 库创建一个应用程序,他们的打印方法有点冗长。 I'm trying to wrap their fprintf function in my own method:
我试图用我自己的方法包装他们的 fprintf 函数:
I would like to turn我想转
FCGX_FPrintF(out, char* fmt, ...);
FCGX_FPrintF(out, char* fmt, ...);
into进入
write(char* strFormat, ...);
写(字符* 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.我发现了 va_list 的神奇之处,但找不到一种简单的方法将 va_list 值传递到它们的 fprintf 函数中。 Is there a way to do this?
有没有办法做到这一点? I know vsprintf and vprintf exist so it must be harder than I imagine it is.
我知道 vsprintf 和 vprintf 存在所以它一定比我想象的要难。
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.您必须在 Fast CGI 库中找到
vfprintf()
的类似物。 It is at least moderately plausible that there is one;至少有一个合理的可能性; the easy way to implement
FCGX_FPrintF()
is:实现
FCGX_FPrintF()
的简单方法是:
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:快速访问Fast CGI 网站会发现 fgciapp.h 头文件中声明的函数使用了 FCGX 前缀,该前缀又包含:
/*
*----------------------------------------------------------------------
*
* 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.
我可能会使用 vsprintf 自己格式化字符串,然后将其发送到打印功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.