本文整理汇总了C++中VSNPRINTF函数的典型用法代码示例。如果您正苦于以下问题:C++ VSNPRINTF函数的具体用法?C++ VSNPRINTF怎么用?C++ VSNPRINTF使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了VSNPRINTF函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ShowErrorVA
static int ShowErrorVA(UINT type, DWORD err, const char *pFmt, va_list va)
{
char buf[1024];
VSNPRINTF(buf, sizeof(buf)/sizeof(buf[0]), pFmt, va);
LPVOID pMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPTSTR) &pMsgBuf,
0,
NULL);
int len = lstrlen(buf);
if ((err & 0xFFFF0000) == 0)
SNPRINTF(buf + len, sizeof(buf)/sizeof(buf[0]) - len, "\nERROR: %lu - %s\n", (unsigned long)err, pMsgBuf);
else
SNPRINTF(buf + len, sizeof(buf)/sizeof(buf[0]) - len, "\nERROR: 0x%08lX - %s\n", (unsigned long)err, pMsgBuf);
LocalFree(pMsgBuf);
return ShowMsg(buf, type);
}
示例2: while
std::string StringUtil::vform(const char* format, va_list args) {
size_t size = 1024;
char* buffer = new char[size];
while (1) {
va_list args_copy;
#if defined(_MSC_VER) || defined(__BORLANDC__)
args_copy = args;
#else
va_copy(args_copy, args);
#endif
int n = VSNPRINTF(buffer, size, format, args_copy);
va_end(args_copy);
// If that worked, return a string.
if ((n > -1) && (static_cast<size_t>(n) < size)) {
std::string s(buffer);
delete [] buffer;
return s;
}
// Else try again with more space.
size = (n > -1) ?
n + 1 : // ISO/IEC 9899:1999
size * 2; // twice the old size
delete [] buffer;
buffer = new char[size];
}
}
示例3: sxe_log_entry
void
sxe_log_entry(unsigned id, unsigned int verbosity, const char * file, int line, const char *fmt, ...)
{
char log_buffer[SXE_LOG_BUFFER_SIZE];
va_list ap;
unsigned i;
unsigned prefix_length;
SXE_CHECK_LOG_INITIALIZE();
SXE_CHECK_VERBOSITY_BEFORE_ANYTHING_ELSE();
prefix_length = sxe_log_buffer_set_prefix(log_buffer, id, verbosity);
i = prefix_length;
va_start(ap, fmt);
if (sxe_log_safe_append(log_buffer, &i, SNPRINTF(&log_buffer[i], SXE_LOG_BUFFER_SIZE - i, "%*s+ ", SXE_LOG_INDENT * 2, ""))
&& sxe_log_safe_append(log_buffer, &i, VSNPRINTF(&log_buffer[i], SXE_LOG_BUFFER_SIZE - i, fmt, ap))) {
sxe_log_safe_append(log_buffer, &i, SNPRINTF(&log_buffer[i], SXE_LOG_BUFFER_SIZE - i, "\n"));
}
sxe_log_line_out_escaped(log_buffer);
i = prefix_length;
sxe_log_safe_append(log_buffer, &i, SNPRINTF(&log_buffer[i], SXE_LOG_BUFFER_SIZE - i, "%*s { // %s:%d\n",
SXE_LOG_INDENT * 2, "", file, line));
sxe_log_line_out_escaped(log_buffer);
SXE_LOG_SET_INDENT(SXE_LOG_INDENT + 1);
} /* sxe_log_entry() */
示例4: send_msg
static int send_msg(process *pp, int act, const char *fmt, ...)
{int nl;
char msg[BFLRG];
char *p;
dbgrsp *gr;
atdbgdes *st;
VA_START(fmt);
if (fmt == NULL)
p = NULL;
else
{VSNPRINTF(msg, BFLRG, fmt);
p = msg;};
VA_END;
gr = (dbgrsp *) pp->a;
st = gr->st;
gr->action = act;
/* log the message sent */
if ((st->log != NULL) && (p != NULL))
fprintf(st->log, "SND: %s\n", p);
nl = job_response(pp, 30000, p);
return(nl);}
示例5: va_start
// Note: This may be Windows specific way of handling
// variable args--there are other methods.
void sml::PrintDebugFormat(char const* pFormat, ...)
{
va_list args;
va_start(args, pFormat);
char szBuffer[10000];
int nBuf = VSNPRINTF(szBuffer, sizeof(szBuffer), pFormat, args);
// was there an error? was the expanded string too long?
if (nBuf < 0)
{
strcpy(szBuffer, "** Debug message too long for PrintDebugFormat's buffer **") ;
}
#ifdef DEBUG_CALLS
CTDebugEnterMethod::PrintStackTrace() ;
PrintDebugMethod(CTDebugEnterMethod::GetCurrentMethodName(), szBuffer) ;
#else
PrintDebugSimple(szBuffer) ;
#endif
va_end(args);
}
示例6: set_last_error
ErrorCode set_last_error( const char* fmt, va_list args )
{
char text[1024];
VSNPRINTF( text, sizeof(text), fmt, args );
mLastError = text;
return MB_SUCCESS;
}
示例7: print_R
/**------------------------------------------------------**/
void print_R(char* out, const char *format, ...)
{
LOG_FILETYPE stderr_f;
char buffer[64];
va_list argptr;
va_start(argptr, format);
VSNPRINTF(buffer, format, argptr);
va_end(argptr);
if(out == NULL)
{
printf_terminal(buffer);
}else
{
if(!monitor_openappend(out,&stderr_f))
{
if(!monitor_openwrite(out,&stderr_f))
{
return;
}
}
/* print to file */
(void)monitor_seek_end(&stderr_f);
(void)monitor_write(buffer,&stderr_f);
(void)monitor_close(&stderr_f);
}
}
示例8: StrcatfHttpResponseBuffer
int StrcatfHttpResponseBuffer( struct HttpEnv *e , char *format , ... )
{
va_list valist ;
long size ;
int len ;
int nret = 0 ;
size = e->rsp_buf->bufsize - e->rsp_buf->len - 1 ;
while(1)
{
va_start( valist , format );
len = VSNPRINTF( e->rsp_buf->ptr , size , format , valist ) ;
va_end( valist );
if( len == -1 || len == size )
{
nret = ReallocHttpBuffer( e->rsp_buf , e->rsp_buf->bufsize * 2 ) ;
if( nret )
return nret;
}
else
{
break;
}
}
e->rsp_buf->ptr += len ;
e->rsp_buf->len += len ;
return 0;
}
示例9: voutf_master_tty
static void
voutf_master_tty (const char * format, va_list args)
{
char buf [1000];
VSNPRINTF (buf, 1000, format, args);
Screen_WriteText (master_tty_window, buf);
}
示例10: WriteLogBaseV
/* 输出日志 */
int WriteLogBaseV( int log_level , char *c_filename , long c_fileline , char *format , va_list valist )
{
char c_filename_copy[ MAXLEN_FILENAME + 1 ] ;
char *p_c_filename = NULL ;
char log_buffer[ 1024 + 1 ] ;
char *log_bufptr = NULL ;
size_t log_buflen ;
size_t log_buf_remain_len ;
size_t len ;
int nret = 0 ;
/* 处理源代码文件名 */
memset( c_filename_copy , 0x00 , sizeof(c_filename_copy) );
strncpy( c_filename_copy , c_filename , sizeof(c_filename_copy)-1 );
p_c_filename = strrchr( c_filename_copy , '\\' ) ;
if( p_c_filename )
p_c_filename++;
else
p_c_filename = c_filename_copy ;
/* 填充行日志 */
/* memset( log_buffer , 0x00 , sizeof(log_buffer) ); */
log_bufptr = log_buffer ;
log_buflen = 0 ;
log_buf_remain_len = sizeof(log_buffer) - 1 - sizeof(NEWLINE) ;
/*
{
struct timeval tv ;
gettimeofday( & tv , NULL );
len = SNPRINTF( log_bufptr , log_buf_remain_len , "%s.%06ld | %-5s | %lu:%lu:%s:%ld | " , g_date_time_cache[g_date_time_cache_index].date_and_time_str , tv.tv_usec , log_level_itoa[log_level] , g_pid , g_tid , p_c_filename , c_fileline ) ;
}
*/
len = SNPRINTF( log_bufptr , log_buf_remain_len , "%s | %-5s | %lu:%lu:%s:%ld | " , g_date_time_cache[g_date_time_cache_index].date_and_time_str , log_level_itoa[log_level] , g_pid , g_tid , p_c_filename , c_fileline ) ;
OFFSET_BUFPTR( log_buffer , log_bufptr , len , log_buflen , log_buf_remain_len );
len = VSNPRINTF( log_bufptr , log_buf_remain_len , format , valist );
OFFSET_BUFPTR( log_buffer , log_bufptr , len , log_buflen , log_buf_remain_len );
log_buf_remain_len += sizeof(NEWLINE) ;
len = SNPRINTF( log_bufptr , log_buf_remain_len , NEWLINE ) ;
OFFSET_BUFPTR( log_buffer , log_bufptr , len , log_buflen , log_buf_remain_len );
/* 输出行日志 */
if( g_file_fd == -1 )
{
nret = OpenLogFile() ;
if( nret )
return nret;
WRITE( g_file_fd , log_buffer , log_buflen );
}
else
{
WRITE( g_file_fd , log_buffer , log_buflen );
}
return 0;
}
示例11: va_copy
void StrBuf::vstrcat(CHAR const* format, va_list args)
{
va_list org_args;
va_copy(org_args, args);
UINT l = VSNPRINTF(NULL, 0, format, args);
strcat(l, format, org_args);
va_end(org_args);
}
示例12: ShowMsgVA
static int ShowMsgVA(UINT type, const char *pFmt, va_list va)
{
char buf[1024];
VSNPRINTF(buf, sizeof(buf)/sizeof(buf[0]), pFmt, va);
return ShowMsg(buf, type);
}
示例13: strformat
static std::string strformat(const char* fmt, ...)
{
char buf[256];
va_list args;
va_start(args,fmt);
VSNPRINTF(buf, sizeof(buf), fmt, args);
va_end(args);
return std::string(buf);
}
示例14: gtm_snprintf
/* Wrapper for snprintf() */
int gtm_snprintf(char *str, size_t size, const char *format, ...)
{
va_list printargs;
int retval;
va_start(printargs, format);
VSNPRINTF(str, size, format, printargs, retval);
va_end(printargs);
return retval;
}
示例15: SPrintf
std::string SPrintf(const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
char buf[512];
VSNPRINTF(buf, sizeof(buf), fmt, ap);
va_end(ap);
return buf;
}