Skip to content

Commit

Permalink
Add str_append_format_va()
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 8, 2017
1 parent d32a939 commit 01d5dd0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,15 @@ void str_append_number( struct str* str, int number ) {
str_append( str, buffer );
}

void str_append_format( struct str* str, const char* format, va_list* args ) {
void str_append_format( struct str* str, const char* format, ... ) {
va_list args;
va_start( args, format );
str_append_format_va( str, format, &args );
va_end( args );
}

void str_append_format_va( struct str* str, const char* format,
va_list* args ) {
va_list args_copy;
va_copy( args_copy, *args );
int length = vsnprintf( NULL, 0, format, *args );
Expand Down
4 changes: 3 additions & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ void str_grow( struct str*, int length );
void str_append( struct str*, const char* cstr );
void str_append_sub( struct str*, const char* cstr, int length );
void str_append_number( struct str*, int number );
void str_append_format( struct str* str, const char* format, va_list* args );
void str_append_format( struct str* str, const char* format, ... );
void str_append_format_va( struct str* str, const char* format,
va_list* args );
void str_clear( struct str* );

// Singly linked list
Expand Down
2 changes: 1 addition & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static void init_diag_msg( struct task* task, struct diag_msg* msg, int flags,
}
// Append message.
const char* format = va_arg( *args, const char* );
str_append_format( &msg->text, format, args );
str_append_format_va( &msg->text, format, args );
}

static void print_diag( struct task* task, struct diag_msg* msg ) {
Expand Down

0 comments on commit 01d5dd0

Please sign in to comment.