在看UEP的时候,作者自定义了几个error_handle函数
#include <stdarg.h> /* ISO C variable aruments */
void err_dump(const char *, ...); /* {App misc_source} */
void err_msg(const char *, ...);
void err_quit(const char *, ...);
void err_exit(int, const char *, ...);
void err_ret(const char *, ...);
void err_sys(const char *, ...);
其中好几个地方都有用到va_start
va_arg
va_end
这几个宏函数,查了一些资料之后将总结记录下来。
首先声明:
测试环境是 GCC:4.8.2
GDB:7.7.1
kernel:3.13.0-36-generic
这几个宏函数主要是针对C语言里的可变参数列表做处理。
参考(还是en好理解):
vsnprintf()
write formatted output to a character array, up to a maximum number of character (varags)
Synopsis:
#include <stdarg.h> #include <stdio.h> int vsnprintf( char* buf, size_t count, const char* format, va_list arg );
Arguments:
buf A pointer to the buffer where you want to function to store the formatted string. count The maximum number of characters to store in the buffer, including a terminating null character. format A string that specifies the format of the output. The formatting string determines what additional arguments you need to provide. For more information, see printf(). arg A variable-argument list of the additional arguments, which you must have initialized with the va_start() macro.
Library:
libc
Description:
The vsnprintf() function formats data under control of the format control string and stores the result in buf. The maximum number of characters to store, including a terminating null character, is specified by count. The vsnprintf() function is a “varargs” version of snprintf().
Returns:
The number of characters that would have been written into the array, not counting the terminating null character