Beispiel #1
0
bool
MyString::vformatstr_cat(const char *format,va_list args) 
{
	char *buffer = NULL;
	int s_len;

    if( !format || *format == '\0' ) {
		return true;
	}
#ifdef HAVE_VASPRINTF
	s_len = vasprintf(&buffer, format, args);
	if (-1 == s_len) { // if alloc not possible or other error
		return false;
	}
#else
    s_len = vprintf_length(format,args);
#endif
    if( Len + s_len > capacity || !Data ) {
		if(!reserve_at_least( Len + s_len )) {
			free(buffer);
			return false;
		}
    }
#ifdef HAVE_VASPRINTF
		// Ideally this would not be necessary, instead we'd just
		// asprintf into Data. However, we manage Data with
		// new/delete.
	memcpy(Data + Len, buffer, s_len + 1);
	free(buffer);
#else
	::vsprintf(Data + Len, format, args);
#endif
	Len += s_len;
    return true;
}
Beispiel #2
0
void CondorError::pushf( const char* the_subsys, int the_code, const char* the_format, ... ) {
	CondorError* tmp = new CondorError();
	tmp->_subsys = strdup(the_subsys);
	tmp->_code = the_code;
	va_list ap;
	va_start(ap, the_format);
	int l = vprintf_length( the_format, ap );
	tmp->_message = (char*)malloc( l+1 );
	if (tmp->_message)
		vsprintf ( tmp->_message, the_format, ap );
	tmp->_next = _next;
	_next = tmp;
	va_end(ap);
}