- int i, i_counter=0, i_pos=0;
- char *psz_dest;
-
- /* We first need to check how many occurences of %ll there are in the
- * psz_format string. Once we'll know that we'll be able to malloc the
- * destination string */
-
- if( strlen( psz_format ) <= 3 )
- return strdup( psz_format );
-
- for( i=0; i <= (strlen(psz_format) - 3); i++ )
- {
- if( !strncmp( (char *)(psz_format + i), "%ll", 3 ) )
- {
- i_counter++;
- }
- }
-
- /* malloc the destination string */
- psz_dest = malloc( strlen(psz_format) + i_counter + 1 );
- if( psz_dest == NULL )
- {
- fprintf( stderr, "main warning: ConvertPrintfFormatString failed\n" );
- return NULL;
- }
-
- /* Now build the modified string */
- i_counter = 0;
- for( i=0; i <= (strlen(psz_format) - 3); i++ )
- {
- if( !strncmp( (char *)(psz_format + i), "%ll", 3 ) )
- {
- memcpy( psz_dest+i_pos+i_counter, psz_format+i_pos, i-i_pos+1);
- *(psz_dest+i+i_counter+1)='I';
- *(psz_dest+i+i_counter+2)='6';
- *(psz_dest+i+i_counter+3)='4';
- i_pos = i+3;
- i_counter++;
- }
- }
- strcpy( psz_dest+i_pos+i_counter, psz_format+i_pos );
-
- return psz_dest;
+ msg_context_t *p_ctx = data;
+
+ free (p_ctx->psz_message);
+ free (p_ctx);
+}
+
+void msg_StackSet( int i_code, const char *psz_message, ... )
+{
+ va_list ap;
+ msg_context_t *p_ctx = GetContext();
+
+ if( p_ctx == NULL )
+ return;
+ free( p_ctx->psz_message );
+
+ va_start( ap, psz_message );
+ if( vasprintf( &p_ctx->psz_message, psz_message, ap ) == -1 )
+ p_ctx->psz_message = NULL;
+ va_end( ap );
+
+ p_ctx->i_code = i_code;
+}
+
+void msg_StackAdd( const char *psz_message, ... )
+{
+ char *psz_tmp;
+ va_list ap;
+ msg_context_t *p_ctx = GetContext();
+
+ if( p_ctx == NULL )
+ return;
+
+ va_start( ap, psz_message );
+ if( vasprintf( &psz_tmp, psz_message, ap ) == -1 )
+ psz_tmp = NULL;
+ va_end( ap );
+
+ if( !p_ctx->psz_message )
+ p_ctx->psz_message = psz_tmp;
+ else
+ {
+ char *psz_new;
+ if( asprintf( &psz_new, "%s: %s", psz_tmp, p_ctx->psz_message ) == -1 )
+ psz_new = NULL;
+
+ free( p_ctx->psz_message );
+ p_ctx->psz_message = psz_new;
+ free( psz_tmp );
+ }
+}
+
+const char* msg_StackMsg( void )
+{
+ msg_context_t *p_ctx = GetContext();
+ assert( p_ctx );
+ return p_ctx->psz_message;